home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gcc_260.zip / gcc_260 / cp / decl.c < prev    next >
C/C++ Source or Header  |  1994-07-13  |  379KB  |  12,031 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include <stdio.h>
  30. #include "config.h"
  31. #include "tree.h"
  32. #include "rtl.h"
  33. #include "flags.h"
  34. #include "cp-tree.h"
  35. #include "decl.h"
  36. #include "lex.h"
  37. #include <sys/types.h>
  38. #include <signal.h>
  39. #include "obstack.h"
  40.  
  41. #define obstack_chunk_alloc xmalloc
  42. #define obstack_chunk_free free
  43.  
  44. extern tree builtin_return_address_fndecl;
  45.  
  46. extern struct obstack permanent_obstack;
  47.  
  48. extern int current_class_depth;
  49.  
  50. extern tree cleanups_this_call;
  51.  
  52. /* Stack of places to restore the search obstack back to.  */
  53.    
  54. /* Obstack used for remembering local class declarations (like
  55.    enums and static (const) members.  */
  56. #include "stack.h"
  57. static struct obstack decl_obstack;
  58. static struct stack_level *decl_stack;
  59.  
  60. #ifndef CHAR_TYPE_SIZE
  61. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  62. #endif
  63.  
  64. #ifndef SHORT_TYPE_SIZE
  65. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  66. #endif
  67.  
  68. #ifndef INT_TYPE_SIZE
  69. #define INT_TYPE_SIZE BITS_PER_WORD
  70. #endif
  71.  
  72. #ifndef LONG_TYPE_SIZE
  73. #define LONG_TYPE_SIZE BITS_PER_WORD
  74. #endif
  75.  
  76. #ifndef LONG_LONG_TYPE_SIZE
  77. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  78. #endif
  79.  
  80. #ifndef WCHAR_UNSIGNED
  81. #define WCHAR_UNSIGNED 0
  82. #endif
  83.  
  84. #ifndef FLOAT_TYPE_SIZE
  85. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  86. #endif
  87.  
  88. #ifndef DOUBLE_TYPE_SIZE
  89. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  90. #endif
  91.  
  92. #ifndef LONG_DOUBLE_TYPE_SIZE
  93. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  94. #endif
  95.  
  96. /* We let tm.h override the types used here, to handle trivial differences
  97.    such as the choice of unsigned int or long unsigned int for size_t.
  98.    When machines start needing nontrivial differences in the size type,
  99.    it would be best to do something here to figure out automatically
  100.    from other information what type to use.  */
  101.  
  102. #ifndef SIZE_TYPE
  103. #define SIZE_TYPE "long unsigned int"
  104. #endif
  105.  
  106. #ifndef PTRDIFF_TYPE
  107. #define PTRDIFF_TYPE "long int"
  108. #endif
  109.  
  110. #ifndef WCHAR_TYPE
  111. #define WCHAR_TYPE "int"
  112. #endif
  113.  
  114. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  115.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  116. #define auto_function(NAME, TYPE, CODE) \
  117.   do {                    \
  118.     tree __name = NAME;        \
  119.     tree __type = TYPE;            \
  120.     define_function (IDENTIFIER_POINTER (__name), __type, CODE,    \
  121.              (void (*)())push_overloaded_decl_1,    \
  122.              IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
  123.   } while (0)
  124.  
  125. static tree grokparms                PROTO((tree, int));
  126. static tree lookup_nested_type            PROTO((tree, tree));
  127. static char *redeclaration_error_message    PROTO((tree, tree));
  128. static void grok_op_properties            PROTO((tree, int, int));
  129.  
  130. tree define_function        
  131.     PROTO((char *, tree, enum built_in_function, void (*)(), char *));
  132.  
  133. /* a node which has tree code ERROR_MARK, and whose type is itself.
  134.    All erroneous expressions are replaced with this node.  All functions
  135.    that accept nodes as arguments should avoid generating error messages
  136.    if this node is one of the arguments, since it is undesirable to get
  137.    multiple error messages from one error in the input.  */
  138.  
  139. tree error_mark_node;
  140.  
  141. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  142. tree error_mark_list;
  143.  
  144. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  145.  
  146. tree short_integer_type_node;
  147. tree integer_type_node;
  148. tree long_integer_type_node;
  149. tree long_long_integer_type_node;
  150.  
  151. tree short_unsigned_type_node;
  152. tree unsigned_type_node;
  153. tree long_unsigned_type_node;
  154. tree long_long_unsigned_type_node;
  155.  
  156. tree ptrdiff_type_node;
  157.  
  158. tree unsigned_char_type_node;
  159. tree signed_char_type_node;
  160. tree char_type_node;
  161. tree wchar_type_node;
  162. tree signed_wchar_type_node;
  163. tree unsigned_wchar_type_node;
  164.  
  165. tree float_type_node;
  166. tree double_type_node;
  167. tree long_double_type_node;
  168.  
  169. tree intQI_type_node;
  170. tree intHI_type_node;
  171. tree intSI_type_node;
  172. tree intDI_type_node;
  173.  
  174. tree unsigned_intQI_type_node;
  175. tree unsigned_intHI_type_node;
  176. tree unsigned_intSI_type_node;
  177. tree unsigned_intDI_type_node;
  178.  
  179. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  180.  
  181. tree void_type_node, void_list_node;
  182. tree void_zero_node;
  183.  
  184. /* Nodes for types `void *' and `const void *'.  */
  185.  
  186. tree ptr_type_node, const_ptr_type_node;
  187.  
  188. /* Nodes for types `char *' and `const char *'.  */
  189.  
  190. tree string_type_node, const_string_type_node;
  191.  
  192. /* Type `char[256]' or something like it.
  193.    Used when an array of char is needed and the size is irrelevant.  */
  194.  
  195. tree char_array_type_node;
  196.  
  197. /* Type `int[256]' or something like it.
  198.    Used when an array of int needed and the size is irrelevant.  */
  199.  
  200. tree int_array_type_node;
  201.  
  202. /* Type `wchar_t[256]' or something like it.
  203.    Used when a wide string literal is created.  */
  204.  
  205. tree wchar_array_type_node;
  206.  
  207. /* The bool data type, and constants */
  208. tree bool_type_node, true_node, false_node;
  209.  
  210. /* type `int ()' -- used for implicit declaration of functions.  */
  211.  
  212. tree default_function_type;
  213.  
  214. /* function types `double (double)' and `double (double, double)', etc.  */
  215.  
  216. tree double_ftype_double, double_ftype_double_double;
  217. tree int_ftype_int, long_ftype_long;
  218.  
  219. /* Function type `void (void *, void *, int)' and similar ones.  */
  220.  
  221. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  222.  
  223. /* Function type `char *(char *, char *)' and similar ones */
  224. tree string_ftype_ptr_ptr, int_ftype_string_string;
  225.  
  226. /* Function type `size_t (const char *)' */
  227. tree sizet_ftype_string;
  228.  
  229. /* Function type `int (const void *, const void *, size_t)' */
  230. tree int_ftype_cptr_cptr_sizet;
  231.  
  232. /* C++ extensions */
  233. tree vtable_entry_type;
  234. tree delta_type_node;
  235. tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
  236. tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
  237. tree class_star_type_node;
  238. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  239. tree exception_type_node, unknown_type_node;
  240. tree opaque_type_node, signature_type_node;
  241. tree sigtable_entry_type;
  242. tree maybe_gc_cleanup;
  243.  
  244. /* Array type `vtable_entry_type[]' */
  245. tree vtbl_type_node;
  246.  
  247. /* In a destructor, the point at which all derived class destroying
  248.    has been done, just before any base class destroying will be done.  */
  249.  
  250. tree dtor_label;
  251.  
  252. /* In a constructor, the point at which we are ready to return
  253.    the pointer to the initialized object.  */
  254.  
  255. tree ctor_label;
  256.  
  257. /* A FUNCTION_DECL which can call `abort'.  Not necessarily the
  258.    one that the user will declare, but sufficient to be called
  259.    by routines that want to abort the program.  */
  260.  
  261. tree abort_fndecl;
  262.  
  263. extern rtx cleanup_label, return_label;
  264.  
  265. /* If original DECL_RESULT of current function was a register,
  266.    but due to being an addressable named return value, would up
  267.    on the stack, this variable holds the named return value's
  268.    original location.  */
  269. rtx original_result_rtx;
  270.  
  271. /* Sequence of insns which represents base initialization.  */
  272. rtx base_init_insns;
  273.  
  274. /* C++: Keep these around to reduce calls to `get_identifier'.
  275.    Identifiers for `this' in member functions and the auto-delete
  276.    parameter for destructors.  */
  277. tree this_identifier, in_charge_identifier;
  278. /* Used in pointer to member functions, and in vtables. */
  279. tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
  280. tree pfn_or_delta2_identifier;
  281.  
  282. /* A list (chain of TREE_LIST nodes) of named label uses.
  283.    The TREE_PURPOSE field is the list of variables defined
  284.    the the label's scope defined at the point of use.
  285.    The TREE_VALUE field is the LABEL_DECL used.
  286.    The TREE_TYPE field holds `current_binding_level' at the
  287.    point of the label's use.
  288.  
  289.    Used only for jumps to as-yet undefined labels, since
  290.    jumps to defined labels can have their validity checked
  291.    by stmt.c.  */
  292.  
  293. static tree named_label_uses;
  294.  
  295. /* A list of objects which have constructors or destructors
  296.    which reside in the global scope.  The decl is stored in
  297.    the TREE_VALUE slot and the initializer is stored
  298.    in the TREE_PURPOSE slot.  */
  299. tree static_aggregates;
  300.  
  301. /* -- end of C++ */
  302.  
  303. /* Two expressions that are constants with value zero.
  304.    The first is of type `int', the second of type `void *'.  */
  305.  
  306. tree integer_zero_node;
  307. tree null_pointer_node;
  308.  
  309. /* A node for the integer constants 1, 2, and 3.  */
  310.  
  311. tree integer_one_node, integer_two_node, integer_three_node;
  312.  
  313. /* Nonzero if we have seen an invalid cross reference
  314.    to a struct, union, or enum, but not yet printed the message.  */
  315.  
  316. tree pending_invalid_xref;
  317. /* File and line to appear in the eventual error message.  */
  318. char *pending_invalid_xref_file;
  319. int pending_invalid_xref_line;
  320.  
  321. /* While defining an enum type, this is 1 plus the last enumerator
  322.    constant value.  */
  323.  
  324. static tree enum_next_value;
  325.  
  326. /* Nonzero means that there was overflow computing enum_next_value.  */
  327.  
  328. static int enum_overflow;
  329.  
  330. /* Parsing a function declarator leaves a list of parameter names
  331.    or a chain or parameter decls here.  */
  332.  
  333. tree last_function_parms;
  334.  
  335. /* Parsing a function declarator leaves here a chain of structure
  336.    and enum types declared in the parmlist.  */
  337.  
  338. static tree last_function_parm_tags;
  339.  
  340. /* After parsing the declarator that starts a function definition,
  341.    `start_function' puts here the list of parameter names or chain of decls.
  342.    `store_parm_decls' finds it here.  */
  343.  
  344. static tree current_function_parms;
  345.  
  346. /* Similar, for last_function_parm_tags.  */
  347. static tree current_function_parm_tags;
  348.  
  349. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  350.    that have names.  Here so we can clear out their names' definitions
  351.    at the end of the function.  */
  352.  
  353. static tree named_labels;
  354.  
  355. /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
  356.  
  357. static tree shadowed_labels;
  358.  
  359. #if 0 /* Not needed by C++ */
  360. /* Nonzero when store_parm_decls is called indicates a varargs function.
  361.    Value not meaningful after store_parm_decls.  */
  362.  
  363. static int c_function_varargs;
  364. #endif
  365.  
  366. /* The FUNCTION_DECL for the function currently being compiled,
  367.    or 0 if between functions.  */
  368. tree current_function_decl;
  369.  
  370. /* Set to 0 at beginning of a function definition, set to 1 if
  371.    a return statement that specifies a return value is seen.  */
  372.  
  373. int current_function_returns_value;
  374.  
  375. /* Set to 0 at beginning of a function definition, set to 1 if
  376.    a return statement with no argument is seen.  */
  377.  
  378. int current_function_returns_null;
  379.  
  380. /* Set to 0 at beginning of a function definition, and whenever
  381.    a label (case or named) is defined.  Set to value of expression
  382.    returned from function when that value can be transformed into
  383.    a named return value.  */
  384.  
  385. tree current_function_return_value;
  386.  
  387. /* Set to nonzero by `grokdeclarator' for a function
  388.    whose return type is defaulted, if warnings for this are desired.  */
  389.  
  390. static int warn_about_return_type;
  391.  
  392. /* Nonzero when starting a function declared `extern inline'.  */
  393.  
  394. static int current_extern_inline;
  395.  
  396. /* Nonzero means give `double' the same size as `float'.  */
  397.  
  398. extern int flag_short_double;
  399.  
  400. /* Nonzero means don't recognize any builtin functions.  */
  401.  
  402. extern int flag_no_builtin;
  403.  
  404. /* Nonzero means disable GNU extensions.  */
  405.  
  406. extern int flag_ansi;
  407.  
  408. /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
  409.    objects. */
  410. extern int flag_huge_objects;
  411.  
  412. /* Nonzero if we want to conserve space in the .o files.  We do this
  413.    by putting uninitialized data and runtime initialized data into
  414.    .common instead of .data at the expense of not flaging multiple
  415.    definitions.  */
  416. extern int flag_conserve_space;
  417.  
  418. /* Pointers to the base and current top of the language name stack.  */
  419.  
  420. extern tree *current_lang_base, *current_lang_stack;
  421.  
  422. /* C and C++ flags are in decl2.c.  */
  423.  
  424. /* Set to 0 at beginning of a constructor, set to 1
  425.    if that function does an allocation before referencing its
  426.    instance variable.  */
  427. int current_function_assigns_this;
  428. int current_function_just_assigned_this;
  429.  
  430. /* Set to 0 at beginning of a function.  Set non-zero when
  431.    store_parm_decls is called.  Don't call store_parm_decls
  432.    if this flag is non-zero!  */
  433. int current_function_parms_stored;
  434.  
  435. /* Current end of entries in the gc obstack for stack pointer variables.  */
  436.  
  437. int current_function_obstack_index;
  438.  
  439. /* Flag saying whether we have used the obstack in this function or not.  */
  440.  
  441. int current_function_obstack_usage;
  442.  
  443. /* Flag used when debugging spew.c */
  444.  
  445. extern int spew_debug;
  446.  
  447. /* This is a copy of the class_shadowed list of the previous class binding
  448.    contour when at global scope.  It's used to reset IDENTIFIER_CLASS_VALUEs
  449.    when entering another class scope (i.e. a cache miss).  */
  450. extern tree previous_class_values;
  451.  
  452.  
  453. /* Allocate a level of searching.  */
  454. struct stack_level *
  455. push_decl_level (stack, obstack)
  456.      struct stack_level *stack;
  457.      struct obstack *obstack;
  458. {
  459.   struct stack_level tem;
  460.   tem.prev = stack;
  461.  
  462.   return push_stack_level (obstack, (char *)&tem, sizeof (tem));
  463. }
  464.  
  465. /* For each binding contour we allocate a binding_level structure
  466.  * which records the names defined in that contour.
  467.  * Contours include:
  468.  *  0) the global one
  469.  *  1) one for each function definition,
  470.  *     where internal declarations of the parameters appear.
  471.  *  2) one for each compound statement,
  472.  *     to record its declarations.
  473.  *
  474.  * The current meaning of a name can be found by searching the levels from
  475.  * the current one out to the global one.
  476.  *
  477.  * Off to the side, may be the class_binding_level.  This exists
  478.  * only to catch class-local declarations.  It is otherwise
  479.  * nonexistent.
  480.  * 
  481.  * Also there may be binding levels that catch cleanups that
  482.  * must be run when exceptions occur.
  483.  */
  484.  
  485. /* Note that the information in the `names' component of the global contour
  486.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  487.  
  488. struct binding_level
  489.   {
  490.     /* A chain of _DECL nodes for all variables, constants, functions,
  491.      * and typedef types.  These are in the reverse of the order supplied.
  492.      */
  493.     tree names;
  494.  
  495.     /* A list of structure, union and enum definitions,
  496.      * for looking up tag names.
  497.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  498.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  499.      * or ENUMERAL_TYPE node.
  500.      *
  501.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  502.      *
  503.      */
  504.     tree tags;
  505.  
  506.     /* For each level, a list of shadowed outer-level local definitions
  507.        to be restored when this level is popped.
  508.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  509.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  510.     tree shadowed;
  511.  
  512.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  513.     tree class_shadowed;
  514.  
  515.     /* Same, for IDENTIFIER_TYPE_VALUE.  */
  516.     tree type_shadowed;
  517.  
  518.     /* For each level (except not the global one),
  519.        a chain of BLOCK nodes for all the levels
  520.        that were entered and exited one level down.  */
  521.     tree blocks;
  522.  
  523.     /* The BLOCK node for this level, if one has been preallocated.
  524.        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
  525.     tree this_block;
  526.  
  527.     /* The binding level which this one is contained in (inherits from).  */
  528.     struct binding_level *level_chain;
  529.  
  530.     /* Number of decls in `names' that have incomplete 
  531.        structure or union types.  */
  532.     unsigned short n_incomplete;
  533.  
  534.     /* 1 for the level that holds the parameters of a function.
  535.        2 for the level that holds a class declaration.
  536.        3 for levels that hold parameter declarations.  */
  537.     unsigned parm_flag : 4;
  538.  
  539.     /* 1 means make a BLOCK for this level regardless of all else.
  540.        2 for temporary binding contours created by the compiler.  */
  541.     unsigned keep : 3;
  542.  
  543.     /* Nonzero if this level "doesn't exist" for tags.  */
  544.     unsigned tag_transparent : 1;
  545.  
  546.     /* Nonzero if this level can safely have additional
  547.        cleanup-needing variables added to it.  */
  548.     unsigned more_cleanups_ok : 1;
  549.     unsigned have_cleanups : 1;
  550.  
  551.     /* Nonzero if we should accept any name as an identifier in
  552.        this scope.  This happens in some template definitions.  */
  553.     unsigned accept_any : 1;
  554.  
  555.     /* Nonzero if this level is for completing a template class definition
  556.        inside a binding level that temporarily binds the parameters.  This
  557.        means that definitions here should not be popped off when unwinding
  558.        this binding level.  (Not actually implemented this way,
  559.        unfortunately.)  */
  560.     unsigned pseudo_global : 1;
  561.  
  562.     /* Two bits left for this word.  */
  563.  
  564. #if defined(DEBUG_CP_BINDING_LEVELS)
  565.     /* Binding depth at which this level began.  */
  566.     unsigned binding_depth;
  567. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  568.   };
  569.  
  570. #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
  571.   
  572. /* The (non-class) binding level currently in effect.  */
  573.  
  574. static struct binding_level *current_binding_level;
  575.  
  576. /* The binding level of the current class, if any.  */
  577.  
  578. static struct binding_level *class_binding_level;
  579.  
  580. /* The current (class or non-class) binding level currently in effect.  */
  581.  
  582. #define inner_binding_level \
  583.   (class_binding_level ? class_binding_level : current_binding_level)
  584.  
  585. /* A chain of binding_level structures awaiting reuse.  */
  586.  
  587. static struct binding_level *free_binding_level;
  588.  
  589. /* The outermost binding level, for names of file scope.
  590.    This is created when the compiler is started and exists
  591.    through the entire run.  */
  592.  
  593. static struct binding_level *global_binding_level;
  594.  
  595. /* Binding level structures are initialized by copying this one.  */
  596.  
  597. static struct binding_level clear_binding_level;
  598.  
  599. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  600.  
  601. static int keep_next_level_flag;
  602.  
  603. #if defined(DEBUG_CP_BINDING_LEVELS)
  604. static int binding_depth = 0;
  605. static int is_class_level = 0;
  606.  
  607. static void
  608. indent ()
  609. {
  610.   register unsigned i;
  611.  
  612.   for (i = 0; i < binding_depth*2; i++)
  613.     putc (' ', stderr);
  614. }
  615. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  616.  
  617. static tree pushdecl_with_scope    PROTO((tree, struct binding_level *));
  618.  
  619. static void
  620. push_binding_level (newlevel, tag_transparent, keep)
  621.      struct binding_level *newlevel;
  622.      int tag_transparent, keep;
  623. {
  624.   /* Add this level to the front of the chain (stack) of levels that
  625.      are active.  */
  626.   *newlevel = clear_binding_level;
  627.   if (class_binding_level)
  628.     {
  629.       newlevel->level_chain = class_binding_level;
  630.       class_binding_level = (struct binding_level *)0;
  631.     }
  632.   else
  633.     {
  634.       newlevel->level_chain = current_binding_level;
  635.     }
  636.   current_binding_level = newlevel;
  637.   newlevel->tag_transparent = tag_transparent;
  638.   newlevel->more_cleanups_ok = 1;
  639.   newlevel->keep = keep;
  640. #if defined(DEBUG_CP_BINDING_LEVELS)
  641.   newlevel->binding_depth = binding_depth;
  642.   indent ();
  643.   fprintf (stderr, "push %s level 0x%08x line %d\n",
  644.        (is_class_level) ? "class" : "block", newlevel, lineno);
  645.   is_class_level = 0;
  646.   binding_depth++;
  647. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  648. }
  649.  
  650. static void
  651. pop_binding_level ()
  652. {
  653.   if (class_binding_level)
  654.     current_binding_level = class_binding_level;
  655.  
  656.   if (global_binding_level)
  657.     {
  658.       /* cannot pop a level, if there are none left to pop. */
  659.       if (current_binding_level == global_binding_level)
  660.     my_friendly_abort (123);
  661.     }
  662.   /* Pop the current level, and free the structure for reuse.  */
  663. #if defined(DEBUG_CP_BINDING_LEVELS)
  664.   binding_depth--;
  665.   indent ();
  666.   fprintf (stderr, "pop  %s level 0x%08x line %d\n",
  667.       (is_class_level) ? "class" : "block",
  668.       current_binding_level, lineno);
  669.   if (is_class_level != (current_binding_level == class_binding_level))
  670. #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
  671.     abort ();
  672. #else
  673.   {
  674.     indent ();
  675.     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
  676.   }
  677. #endif
  678.   is_class_level = 0;
  679. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  680.   {
  681.     register struct binding_level *level = current_binding_level;
  682.     current_binding_level = current_binding_level->level_chain;
  683.     level->level_chain = free_binding_level;
  684. #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
  685.     if (level->binding_depth != binding_depth)
  686.       abort ();
  687. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  688.       free_binding_level = level;
  689.  
  690.     class_binding_level = current_binding_level;
  691.     if (class_binding_level->parm_flag != 2)
  692.       class_binding_level = 0;
  693.     while (current_binding_level->parm_flag == 2)
  694.       current_binding_level = current_binding_level->level_chain;
  695.   }
  696. }
  697.  
  698. /* Nonzero if we are currently in the global binding level.  */
  699.  
  700. int
  701. global_bindings_p ()
  702. {
  703.   return current_binding_level == global_binding_level;
  704. }
  705.  
  706. void
  707. keep_next_level ()
  708. {
  709.   keep_next_level_flag = 1;
  710. }
  711.  
  712. /* Nonzero if the current level needs to have a BLOCK made.  */
  713.  
  714. int
  715. kept_level_p ()
  716. {
  717.   return (current_binding_level->blocks != NULL_TREE
  718.       || current_binding_level->keep
  719.       || current_binding_level->names != NULL_TREE
  720.       || (current_binding_level->tags != NULL_TREE
  721.           && !current_binding_level->tag_transparent));
  722. }
  723.  
  724. /* Identify this binding level as a level of parameters.  */
  725.  
  726. void
  727. declare_parm_level ()
  728. {
  729.   current_binding_level->parm_flag = 1;
  730. }
  731.  
  732. void
  733. declare_uninstantiated_type_level ()
  734. {
  735.   current_binding_level->accept_any = 1;
  736. }
  737.  
  738. int
  739. uninstantiated_type_level_p ()
  740. {
  741.   return current_binding_level->accept_any;
  742. }
  743.  
  744. void
  745. declare_pseudo_global_level ()
  746. {
  747.   current_binding_level->pseudo_global = 1;
  748. }
  749.  
  750. int
  751. pseudo_global_level_p ()
  752. {
  753.   return current_binding_level->pseudo_global;
  754. }
  755.  
  756. void
  757. set_class_shadows (shadows)
  758.      tree shadows;
  759. {
  760.   class_binding_level->class_shadowed = shadows;
  761. }
  762.  
  763. /* Enter a new binding level.
  764.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  765.    not for that of tags.  */
  766.  
  767. void
  768. pushlevel (tag_transparent)
  769.      int tag_transparent;
  770. {
  771.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  772.  
  773.   /* If this is the top level of a function,
  774.      just make sure that NAMED_LABELS is 0.
  775.      They should have been set to 0 at the end of the previous function.  */
  776.  
  777.   if (current_binding_level == global_binding_level)
  778.     my_friendly_assert (named_labels == NULL_TREE, 134);
  779.  
  780.   /* Reuse or create a struct for this binding level.  */
  781.  
  782. #if defined(DEBUG_CP_BINDING_LEVELS)
  783.   if (0)
  784. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  785.   if (free_binding_level)
  786. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  787.     {
  788.       newlevel = free_binding_level;
  789.       free_binding_level = free_binding_level->level_chain;
  790.     }
  791.   else
  792.     {
  793.       /* Create a new `struct binding_level'.  */
  794.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  795.     }
  796.   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
  797.   GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
  798.   keep_next_level_flag = 0;
  799. }
  800.  
  801. void
  802. pushlevel_temporary (tag_transparent)
  803.      int tag_transparent;
  804. {
  805.   pushlevel (tag_transparent);
  806.   current_binding_level->keep = 2;
  807.   clear_last_expr ();
  808.  
  809.   /* Note we don't call push_momentary() here.  Otherwise, it would cause
  810.      cleanups to be allocated on the momentary obstack, and they will be
  811.      overwritten by the next statement.  */
  812.  
  813.   expand_start_bindings (0);
  814. }
  815.  
  816. /* Exit a binding level.
  817.    Pop the level off, and restore the state of the identifier-decl mappings
  818.    that were in effect when this level was entered.
  819.  
  820.    If KEEP == 1, this level had explicit declarations, so
  821.    and create a "block" (a BLOCK node) for the level
  822.    to record its declarations and subblocks for symbol table output.
  823.  
  824.    If KEEP == 2, this level's subblocks go to the front,
  825.    not the back of the current binding level.  This happens,
  826.    for instance, when code for constructors and destructors
  827.    need to generate code at the end of a function which must
  828.    be moved up to the front of the function.
  829.  
  830.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  831.    so create a block as if KEEP were set and also clear out all
  832.    label names.
  833.  
  834.    If REVERSE is nonzero, reverse the order of decls before putting
  835.    them into the BLOCK.  */
  836.  
  837. tree
  838. poplevel (keep, reverse, functionbody)
  839.      int keep;
  840.      int reverse;
  841.      int functionbody;
  842. {
  843.   register tree link;
  844.   /* The chain of decls was accumulated in reverse order.
  845.      Put it into forward order, just for cleanliness.  */
  846.   tree decls;
  847.   int tmp = functionbody;
  848.   int implicit_try_block = current_binding_level->parm_flag == 3;
  849.   int real_functionbody = current_binding_level->keep == 2
  850.     ? ((functionbody = 0), tmp) : functionbody;
  851.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  852.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  853.   tree block = NULL_TREE;
  854.   tree decl;
  855.   int block_previously_created;
  856.  
  857.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  858.               (HOST_WIDE_INT) current_binding_level->level_chain,
  859.               current_binding_level->parm_flag,
  860.               current_binding_level->keep,
  861.               current_binding_level->tag_transparent);
  862.  
  863.   if (current_binding_level->keep == 1)
  864.     keep = 1;
  865.  
  866.   /* This warning is turned off because it causes warnings for
  867.      declarations like `extern struct foo *x'.  */
  868. #if 0
  869.   /* Warn about incomplete structure types in this level.  */
  870.   for (link = tags; link; link = TREE_CHAIN (link))
  871.     if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
  872.       {
  873.     tree type = TREE_VALUE (link);
  874.     char *errmsg;
  875.     switch (TREE_CODE (type))
  876.       {
  877.       case RECORD_TYPE:
  878.         errmsg = "`struct %s' incomplete in scope ending here";
  879.         break;
  880.       case UNION_TYPE:
  881.         errmsg = "`union %s' incomplete in scope ending here";
  882.         break;
  883.       case ENUMERAL_TYPE:
  884.         errmsg = "`enum %s' incomplete in scope ending here";
  885.         break;
  886.       }
  887.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  888.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  889.     else
  890.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  891.       error (errmsg, TYPE_NAME_STRING (type));
  892.       }
  893. #endif /* 0 */
  894.  
  895.   /* Get the decls in the order they were written.
  896.      Usually current_binding_level->names is in reverse order.
  897.      But parameter decls were previously put in forward order.  */
  898.  
  899.   if (reverse)
  900.     current_binding_level->names
  901.       = decls = nreverse (current_binding_level->names);
  902.   else
  903.     decls = current_binding_level->names;
  904.  
  905.   /* Output any nested inline functions within this block
  906.      if they weren't already output.  */
  907.  
  908.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  909.     if (TREE_CODE (decl) == FUNCTION_DECL
  910.     && ! TREE_ASM_WRITTEN (decl)
  911.     && DECL_INITIAL (decl) != NULL_TREE
  912.     && TREE_ADDRESSABLE (decl))
  913.       {
  914.     /* If this decl was copied from a file-scope decl
  915.        on account of a block-scope extern decl,
  916.        propagate TREE_ADDRESSABLE to the file-scope decl.  */
  917.     if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
  918.       TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
  919.     else
  920.       {
  921.         push_function_context ();
  922.         output_inline_function (decl);
  923.         pop_function_context ();
  924.       }
  925.       }
  926.  
  927.   /* If there were any declarations or structure tags in that level,
  928.      or if this level is a function body,
  929.      create a BLOCK to record them for the life of this function.  */
  930.  
  931.   block = NULL_TREE;
  932.   block_previously_created = (current_binding_level->this_block != NULL_TREE);
  933.   if (block_previously_created)
  934.     block = current_binding_level->this_block;
  935.   else if (keep == 1 || functionbody)
  936.     block = make_node (BLOCK);
  937.   if (block != NULL_TREE)
  938.     {
  939.       BLOCK_VARS (block) = decls;
  940.       BLOCK_TYPE_TAGS (block) = tags;
  941.       BLOCK_SUBBLOCKS (block) = subblocks;
  942.       /* If we created the block earlier on, and we are just diddling it now,
  943.      then it already should have a proper BLOCK_END_NOTE value associated
  944.      with it, so avoid trashing that.  Otherwise, for a new block, install
  945.      a new BLOCK_END_NOTE value.  */
  946.       if (! block_previously_created)
  947.     remember_end_note (block);
  948.     }
  949.  
  950.   /* In each subblock, record that this is its superior.  */
  951.  
  952.   if (keep >= 0)
  953.     for (link = subblocks; link; link = TREE_CHAIN (link))
  954.       BLOCK_SUPERCONTEXT (link) = block;
  955.  
  956.   /* Clear out the meanings of the local variables of this level.  */
  957.  
  958.   for (link = decls; link; link = TREE_CHAIN (link))
  959.     {
  960.       if (DECL_NAME (link) != NULL_TREE)
  961.     {
  962.       /* If the ident. was used or addressed via a local extern decl,
  963.          don't forget that fact.  */
  964.       if (DECL_EXTERNAL (link))
  965.         {
  966.           if (TREE_USED (link))
  967.         TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  968.           if (TREE_ADDRESSABLE (link))
  969.         TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  970.         }
  971.       IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
  972.     }
  973.     }
  974.  
  975.   /* Restore all name-meanings of the outer levels
  976.      that were shadowed by this level.  */
  977.  
  978.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  979.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  980.   for (link = current_binding_level->class_shadowed;
  981.        link; link = TREE_CHAIN (link))
  982.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  983.   for (link = current_binding_level->type_shadowed;
  984.        link; link = TREE_CHAIN (link))
  985.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  986.  
  987.   /* If the level being exited is the top level of a function,
  988.      check over all the labels.  */
  989.  
  990.   if (functionbody)
  991.     {
  992.       /* If this is the top level block of a function,
  993.          the vars are the function's parameters.
  994.          Don't leave them in the BLOCK because they are
  995.          found in the FUNCTION_DECL instead.  */
  996.  
  997.       BLOCK_VARS (block) = 0;
  998.  
  999.       /* Clear out the definitions of all label names,
  1000.      since their scopes end here.  */
  1001.  
  1002.       for (link = named_labels; link; link = TREE_CHAIN (link))
  1003.     {
  1004.       register tree label = TREE_VALUE (link);
  1005.  
  1006.       if (DECL_INITIAL (label) == NULL_TREE)
  1007.         {
  1008.           cp_error_at ("label `%D' used but not defined", label);
  1009.           /* Avoid crashing later.  */
  1010.           define_label (input_filename, 1, DECL_NAME (label));
  1011.         }
  1012.       else if (warn_unused && !TREE_USED (label))
  1013.         cp_warning_at ("label `%D' defined but not used", label);
  1014.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
  1015.  
  1016.           /* Put the labels into the "variables" of the
  1017.              top-level block, so debugger can see them.  */
  1018.           TREE_CHAIN (label) = BLOCK_VARS (block);
  1019.           BLOCK_VARS (block) = label;
  1020.     }
  1021.  
  1022.       named_labels = NULL_TREE;
  1023.     }
  1024.  
  1025.   /* Any uses of undefined labels now operate under constraints
  1026.      of next binding contour.  */
  1027.   {
  1028.     struct binding_level *level_chain;
  1029.     level_chain = current_binding_level->level_chain;
  1030.     if (level_chain)
  1031.       {
  1032.     tree labels;
  1033.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  1034.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  1035.         {
  1036.           TREE_TYPE (labels) = (tree)level_chain;
  1037.           TREE_PURPOSE (labels) = level_chain->names;
  1038.         }
  1039.       }
  1040.   }
  1041.  
  1042.   tmp = current_binding_level->keep;
  1043.  
  1044.   pop_binding_level ();
  1045.   if (functionbody)
  1046.     DECL_INITIAL (current_function_decl) = block;
  1047.   else if (block)
  1048.     {
  1049.       if (!block_previously_created)
  1050.         current_binding_level->blocks
  1051.           = chainon (current_binding_level->blocks, block);
  1052.     }
  1053.   /* If we did not make a block for the level just exited,
  1054.      any blocks made for inner levels
  1055.      (since they cannot be recorded as subblocks in that level)
  1056.      must be carried forward so they will later become subblocks
  1057.      of something else.  */
  1058.   else if (subblocks)
  1059.     {
  1060.       if (keep == 2)
  1061.     current_binding_level->blocks
  1062.       = chainon (subblocks, current_binding_level->blocks);
  1063.       else
  1064.     current_binding_level->blocks
  1065.       = chainon (current_binding_level->blocks, subblocks);
  1066.     }
  1067.  
  1068.   /* Take care of compiler's internal binding structures.  */
  1069.   if (tmp == 2)
  1070.     {
  1071. #if 0
  1072.       /* We did not call push_momentary for this
  1073.      binding contour, so there is nothing to pop.  */
  1074.       pop_momentary ();
  1075. #endif
  1076.       expand_end_bindings (getdecls (), keep, 1);
  1077.       /* Each and every BLOCK node created here in `poplevel' is important
  1078.      (e.g. for proper debugging information) so if we created one
  1079.      earlier, mark it as "used".  */
  1080.       if (block)
  1081.     TREE_USED (block) = 1;
  1082.       block = poplevel (keep, reverse, real_functionbody);
  1083.     }
  1084.  
  1085.   /* Each and every BLOCK node created here in `poplevel' is important
  1086.      (e.g. for proper debugging information) so if we created one
  1087.      earlier, mark it as "used".  */
  1088.   if (block)
  1089.     TREE_USED (block) = 1;
  1090.   return block;
  1091. }
  1092.  
  1093. /* Delete the node BLOCK from the current binding level.
  1094.    This is used for the block inside a stmt expr ({...})
  1095.    so that the block can be reinserted where appropriate.  */
  1096.  
  1097. void
  1098. delete_block (block)
  1099.      tree block;
  1100. {
  1101.   tree t;
  1102.   if (current_binding_level->blocks == block)
  1103.     current_binding_level->blocks = TREE_CHAIN (block);
  1104.   for (t = current_binding_level->blocks; t;)
  1105.     {
  1106.       if (TREE_CHAIN (t) == block)
  1107.     TREE_CHAIN (t) = TREE_CHAIN (block);
  1108.       else
  1109.     t = TREE_CHAIN (t);
  1110.     }
  1111.   TREE_CHAIN (block) = NULL_TREE;
  1112.   /* Clear TREE_USED which is always set by poplevel.
  1113.      The flag is set again if insert_block is called.  */
  1114.   TREE_USED (block) = 0;
  1115. }
  1116.  
  1117. /* Insert BLOCK at the end of the list of subblocks of the
  1118.    current binding level.  This is used when a BIND_EXPR is expanded,
  1119.    to handle the BLOCK node inside the BIND_EXPR.  */
  1120.  
  1121. void
  1122. insert_block (block)
  1123.      tree block;
  1124. {
  1125.   TREE_USED (block) = 1;
  1126.   current_binding_level->blocks
  1127.     = chainon (current_binding_level->blocks, block);
  1128. }
  1129.  
  1130. /* Add BLOCK to the current list of blocks for this binding contour.  */
  1131. void
  1132. add_block_current_level (block)
  1133.      tree block;
  1134. {
  1135.   current_binding_level->blocks
  1136.     = chainon (current_binding_level->blocks, block);
  1137. }
  1138.  
  1139. /* Set the BLOCK node for the innermost scope
  1140.    (the one we are currently in).  */
  1141.  
  1142. void
  1143. set_block (block)
  1144.     register tree block;
  1145. {
  1146.   current_binding_level->this_block = block;
  1147. }
  1148.  
  1149. /* Do a pushlevel for class declarations.  */
  1150. void
  1151. pushlevel_class ()
  1152. {
  1153.   register struct binding_level *newlevel;
  1154.  
  1155.   /* Reuse or create a struct for this binding level.  */
  1156. #if defined(DEBUG_CP_BINDING_LEVELS)
  1157.   if (0)
  1158. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1159.   if (free_binding_level)
  1160. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1161.     {
  1162.       newlevel = free_binding_level;
  1163.       free_binding_level = free_binding_level->level_chain;
  1164.     }
  1165.   else
  1166.     {
  1167.       /* Create a new `struct binding_level'.  */
  1168.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  1169.     }
  1170.  
  1171. #if defined(DEBUG_CP_BINDING_LEVELS)
  1172.   is_class_level = 1;
  1173. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1174.  
  1175.   push_binding_level (newlevel, 0, 0);
  1176.  
  1177.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  1178.   class_binding_level = current_binding_level;
  1179.   class_binding_level->parm_flag = 2;
  1180.   /* We have just pushed into a new binding level.  Now, fake out the rest
  1181.      of the compiler.  Set the `current_binding_level' back to point to
  1182.      the most closely containing non-class binding level.  */
  1183.   do
  1184.     {
  1185.       current_binding_level = current_binding_level->level_chain;
  1186.     }
  1187.   while (current_binding_level->parm_flag == 2);
  1188. }
  1189.  
  1190. /* ...and a poplevel for class declarations.  FORCE is used to force
  1191.    clearing out of CLASS_VALUEs after a class definition.  */
  1192. tree
  1193. poplevel_class (force)
  1194.      int force;
  1195. {
  1196.   register struct binding_level *level = class_binding_level;
  1197.   tree block = NULL_TREE;
  1198.   tree shadowed;
  1199.  
  1200.   my_friendly_assert (level != 0, 354);
  1201.   
  1202.   decl_stack = pop_stack_level (decl_stack);
  1203.   for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1204.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1205.   /* If we're leaving a toplevel class, don't bother to do the setting
  1206.      of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
  1207.      shouldn't even be used when current_class_type isn't set, and second,
  1208.      if we don't touch it here, we're able to use the caching effect if the
  1209.      next time we're entering a class scope, it is the same class.  */
  1210.   if (current_class_depth != 1 || force)
  1211.     for (shadowed = level->class_shadowed;
  1212.      shadowed;
  1213.      shadowed = TREE_CHAIN (shadowed))
  1214.       IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1215.   else
  1216.     /* Remember to save what IDENTIFIER's were bound in this scope so we
  1217.        can recover from cache misses.  */
  1218.     previous_class_values = class_binding_level->class_shadowed;
  1219.   for (shadowed = level->type_shadowed;
  1220.        shadowed;
  1221.        shadowed = TREE_CHAIN (shadowed))
  1222.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1223.  
  1224.   GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
  1225.               (HOST_WIDE_INT) class_binding_level->level_chain,
  1226.               class_binding_level->parm_flag,
  1227.               class_binding_level->keep,
  1228.               class_binding_level->tag_transparent);
  1229.  
  1230.   if (class_binding_level->parm_flag != 2)
  1231.     class_binding_level = (struct binding_level *)0;
  1232.  
  1233.   /* Now, pop out of the the binding level which we created up in the
  1234.      `pushlevel_class' routine.  */
  1235. #if defined(DEBUG_CP_BINDING_LEVELS)
  1236.   is_class_level = 1;
  1237. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1238.  
  1239.   pop_binding_level ();
  1240.  
  1241.   return block;
  1242. }
  1243.  
  1244. /* For debugging.  */
  1245. int no_print_functions = 0;
  1246. int no_print_builtins = 0;
  1247.  
  1248. void
  1249. print_binding_level (lvl)
  1250.      struct binding_level *lvl;
  1251. {
  1252.   tree t;
  1253.   int i = 0, len;
  1254.   fprintf (stderr, " blocks=");
  1255.   fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
  1256.   fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
  1257.        lvl->n_incomplete, lvl->parm_flag, lvl->keep);
  1258.   if (lvl->tag_transparent)
  1259.     fprintf (stderr, " tag-transparent");
  1260.   if (lvl->more_cleanups_ok)
  1261.     fprintf (stderr, " more-cleanups-ok");
  1262.   if (lvl->have_cleanups)
  1263.     fprintf (stderr, " have-cleanups");
  1264.   fprintf (stderr, "\n");
  1265.   if (lvl->names)
  1266.     {
  1267.       fprintf (stderr, " names:\t");
  1268.       /* We can probably fit 3 names to a line?  */
  1269.       for (t = lvl->names; t; t = TREE_CHAIN (t))
  1270.     {
  1271.       if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 
  1272.         continue;
  1273.       if (no_print_builtins
  1274.           && (TREE_CODE(t) == TYPE_DECL)
  1275.           && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
  1276.         continue;
  1277.  
  1278.       /* Function decls tend to have longer names.  */
  1279.       if (TREE_CODE (t) == FUNCTION_DECL)
  1280.         len = 3;
  1281.       else
  1282.         len = 2;
  1283.       i += len;
  1284.       if (i > 6)
  1285.         {
  1286.           fprintf (stderr, "\n\t");
  1287.           i = len;
  1288.         }
  1289.       print_node_brief (stderr, "", t, 0);
  1290.       if (TREE_CODE (t) == ERROR_MARK)
  1291.         break;
  1292.     }
  1293.       if (i)
  1294.         fprintf (stderr, "\n");
  1295.     }
  1296.   if (lvl->tags)
  1297.     {
  1298.       fprintf (stderr, " tags:\t");
  1299.       i = 0;
  1300.       for (t = lvl->tags; t; t = TREE_CHAIN (t))
  1301.     {
  1302.       if (TREE_PURPOSE (t) == NULL_TREE)
  1303.         len = 3;
  1304.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1305.         len = 2;
  1306.       else
  1307.         len = 4;
  1308.       i += len;
  1309.       if (i > 5)
  1310.         {
  1311.           fprintf (stderr, "\n\t");
  1312.           i = len;
  1313.         }
  1314.       if (TREE_PURPOSE (t) == NULL_TREE)
  1315.         {
  1316.           print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
  1317.           fprintf (stderr, ">");
  1318.         }
  1319.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1320.         print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1321.       else
  1322.         {
  1323.           print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
  1324.           print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1325.           fprintf (stderr, ">");
  1326.         }
  1327.     }
  1328.       if (i)
  1329.     fprintf (stderr, "\n");
  1330.     }
  1331.   if (lvl->shadowed)
  1332.     {
  1333.       fprintf (stderr, " shadowed:");
  1334.       for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
  1335.     {
  1336.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1337.     }
  1338.       fprintf (stderr, "\n");
  1339.     }
  1340.   if (lvl->class_shadowed)
  1341.     {
  1342.       fprintf (stderr, " class-shadowed:");
  1343.       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
  1344.     {
  1345.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1346.     }
  1347.       fprintf (stderr, "\n");
  1348.     }
  1349.   if (lvl->type_shadowed)
  1350.     {
  1351.       fprintf (stderr, " type-shadowed:");
  1352.       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
  1353.         {
  1354. #if 0
  1355.           fprintf (stderr, "\n\t");
  1356.           print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
  1357.           if (TREE_VALUE (t))
  1358.             print_node_brief (stderr, " ", TREE_VALUE (t), 0);
  1359.           else
  1360.             fprintf (stderr, " (none)");
  1361.           fprintf (stderr, ">");
  1362. #else
  1363.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1364. #endif
  1365.         }
  1366.       fprintf (stderr, "\n");
  1367.     }
  1368. }
  1369.  
  1370. void
  1371. print_other_binding_stack (stack)
  1372.      struct binding_level *stack;
  1373. {
  1374.   struct binding_level *level;
  1375.   for (level = stack; level != global_binding_level; level = level->level_chain)
  1376.     {
  1377.       fprintf (stderr, "binding level ");
  1378.       fprintf (stderr, HOST_PTR_PRINTF, level);
  1379.       fprintf (stderr, "\n");
  1380.       print_binding_level (level);
  1381.     }
  1382. }
  1383.  
  1384. void
  1385. print_binding_stack ()
  1386. {
  1387.   struct binding_level *b;
  1388.   fprintf (stderr, "current_binding_level=");
  1389.   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
  1390.   fprintf (stderr, "\nclass_binding_level=");
  1391.   fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
  1392.   fprintf (stderr, "\nglobal_binding_level=");
  1393.   fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
  1394.   fprintf (stderr, "\n");
  1395.   if (class_binding_level)
  1396.     {
  1397.       for (b = class_binding_level; b; b = b->level_chain)
  1398.     if (b == current_binding_level)
  1399.       break;
  1400.       if (b)
  1401.     b = class_binding_level;
  1402.       else
  1403.     b = current_binding_level;
  1404.     }
  1405.   else
  1406.     b = current_binding_level;
  1407.   print_other_binding_stack (b);
  1408.   fprintf (stderr, "global:\n");
  1409.   print_binding_level (global_binding_level);
  1410. }
  1411.  
  1412. /* Subroutines for reverting temporarily to top-level for instantiation
  1413.    of templates and such.  We actually need to clear out the class- and
  1414.    local-value slots of all identifiers, so that only the global values
  1415.    are at all visible.  Simply setting current_binding_level to the global
  1416.    scope isn't enough, because more binding levels may be pushed.  */
  1417. struct saved_scope {
  1418.   struct binding_level *old_binding_level;
  1419.   tree old_bindings;
  1420.   struct saved_scope *prev;
  1421.   tree class_name, class_type, class_decl, function_decl;
  1422.   struct binding_level *class_bindings;
  1423.   tree previous_class_type;
  1424.   tree *lang_base, *lang_stack, lang_name;
  1425.   int lang_stacksize;
  1426.   tree named_labels;
  1427. };
  1428. static struct saved_scope *current_saved_scope;
  1429. extern tree prev_class_type;
  1430.  
  1431. void
  1432. push_to_top_level ()
  1433. {
  1434.   extern int current_lang_stacksize;
  1435.   struct saved_scope *s =
  1436.     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
  1437.   struct binding_level *b = current_binding_level;
  1438.   tree old_bindings = NULL_TREE;
  1439.  
  1440.   /* Have to include global_binding_level, because class-level decls
  1441.      aren't listed anywhere useful.  */
  1442.   for (; b; b = b->level_chain)
  1443.     {
  1444.       tree t;
  1445.  
  1446.       if (b == global_binding_level)
  1447.     continue;
  1448.       
  1449.       for (t = b->names; t; t = TREE_CHAIN (t))
  1450.     {
  1451.       tree binding, t1, t2 = t;
  1452.       tree id = DECL_ASSEMBLER_NAME (t2);
  1453.  
  1454.       if (!id
  1455.           || (!IDENTIFIER_LOCAL_VALUE (id)
  1456.           && !IDENTIFIER_CLASS_VALUE (id)))
  1457.         continue;
  1458.  
  1459.       for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
  1460.         if (TREE_VEC_ELT (t1, 0) == id)
  1461.           goto skip_it;
  1462.         
  1463.       binding = make_tree_vec (4);
  1464.       if (id)
  1465.         {
  1466.           my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
  1467.           TREE_VEC_ELT (binding, 0) = id;
  1468.           TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
  1469.           TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
  1470.           TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
  1471.           IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
  1472.           IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
  1473.         }
  1474.       TREE_CHAIN (binding) = old_bindings;
  1475.       old_bindings = binding;
  1476.     skip_it:
  1477.       ;
  1478.     }
  1479.       /* Unwind type-value slots back to top level.  */
  1480.       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  1481.     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
  1482.     }
  1483.   /* Clear out class-level bindings cache.  */
  1484.   if (current_binding_level == global_binding_level
  1485.       && previous_class_type != NULL_TREE)
  1486.     {
  1487.       popclass (-1);
  1488.       previous_class_type = NULL_TREE;
  1489.     }
  1490.  
  1491.   s->old_binding_level = current_binding_level;
  1492.   current_binding_level = global_binding_level;
  1493.  
  1494.   s->class_name = current_class_name;
  1495.   s->class_type = current_class_type;
  1496.   s->class_decl = current_class_decl;
  1497.   s->function_decl = current_function_decl;
  1498.   s->class_bindings = class_binding_level;
  1499.   s->previous_class_type = previous_class_type;
  1500.   s->lang_stack = current_lang_stack;
  1501.   s->lang_base = current_lang_base;
  1502.   s->lang_stacksize = current_lang_stacksize;
  1503.   s->lang_name = current_lang_name;
  1504.   s->named_labels = named_labels;
  1505.   current_class_name = current_class_type = current_class_decl = NULL_TREE;
  1506.   current_function_decl = NULL_TREE;
  1507.   class_binding_level = (struct binding_level *)0;
  1508.   previous_class_type = NULL_TREE;
  1509.   current_lang_stacksize = 10;
  1510.   current_lang_stack = current_lang_base
  1511.     = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
  1512.   current_lang_name = lang_name_cplusplus;
  1513.   strict_prototype = strict_prototypes_lang_cplusplus;
  1514.   named_labels = NULL_TREE;
  1515.  
  1516.   s->prev = current_saved_scope;
  1517.   s->old_bindings = old_bindings;
  1518.   current_saved_scope = s;
  1519. }
  1520.  
  1521. void
  1522. pop_from_top_level ()
  1523. {
  1524.   extern int current_lang_stacksize;
  1525.   struct saved_scope *s = current_saved_scope;
  1526.   tree t;
  1527.  
  1528.   if (previous_class_type)
  1529.     previous_class_type = NULL_TREE;
  1530.  
  1531.   current_binding_level = s->old_binding_level;
  1532.   current_saved_scope = s->prev;
  1533.   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
  1534.     {
  1535.       tree id = TREE_VEC_ELT (t, 0);
  1536.       if (id)
  1537.     {
  1538.       IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
  1539.       IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
  1540.       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
  1541.     }
  1542.     }
  1543.   current_class_name = s->class_name;
  1544.   current_class_type = s->class_type;
  1545.   current_class_decl = s->class_decl;
  1546.   if (current_class_type)
  1547.     C_C_D = CLASSTYPE_INST_VAR (current_class_type);
  1548.   else
  1549.     C_C_D = NULL_TREE;
  1550.   current_function_decl = s->function_decl;
  1551.   class_binding_level = s->class_bindings;
  1552.   previous_class_type = s->previous_class_type;
  1553.   free (current_lang_base);
  1554.   current_lang_base = s->lang_base;
  1555.   current_lang_stack = s->lang_stack;
  1556.   current_lang_name = s->lang_name;
  1557.   current_lang_stacksize = s->lang_stacksize;
  1558.   if (current_lang_name == lang_name_cplusplus)
  1559.     strict_prototype = strict_prototypes_lang_cplusplus;
  1560.   else if (current_lang_name == lang_name_c)
  1561.     strict_prototype = strict_prototypes_lang_c;
  1562.   named_labels = s->named_labels;
  1563.  
  1564.   free (s);
  1565. }
  1566.  
  1567. /* Push a definition of struct, union or enum tag "name".
  1568.    into binding_level "b".   "type" should be the type node, 
  1569.    We assume that the tag "name" is not already defined.
  1570.  
  1571.    Note that the definition may really be just a forward reference.
  1572.    In that case, the TYPE_SIZE will be a NULL_TREE.
  1573.  
  1574.    C++ gratuitously puts all these tags in the name space. */
  1575.  
  1576. /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
  1577.    record the shadowed value for this binding contour.  TYPE is
  1578.    the type that ID maps to.  */
  1579.  
  1580. static void
  1581. set_identifier_type_value_with_scope (id, type, b)
  1582.      tree id;
  1583.      tree type;
  1584.      struct binding_level *b;
  1585. {
  1586.   if (b != global_binding_level)
  1587.     {
  1588.       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
  1589.       b->type_shadowed
  1590.     = tree_cons (id, old_type_value, b->type_shadowed);
  1591.     }
  1592.   SET_IDENTIFIER_TYPE_VALUE (id, type);
  1593. }
  1594.  
  1595. /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
  1596.  
  1597. void
  1598. set_identifier_type_value (id, type)
  1599.      tree id;
  1600.      tree type;
  1601. {
  1602.   set_identifier_type_value_with_scope (id, type, inner_binding_level);
  1603. }
  1604.  
  1605. /* Subroutine "set_nested_typename" builds the nested-typename of
  1606.    the type decl in question.  (Argument CLASSNAME can actually be
  1607.    a function as well, if that's the smallest containing scope.)  */
  1608.  
  1609. static void
  1610. set_nested_typename (decl, classname, name, type)
  1611.      tree decl, classname, name, type;
  1612. {
  1613.   my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
  1614.   if (classname != NULL_TREE)
  1615.     {
  1616.       char *buf;
  1617.       my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
  1618.       my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
  1619.       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
  1620.                  + IDENTIFIER_LENGTH (name));
  1621.       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
  1622.            IDENTIFIER_POINTER (name));
  1623.       DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
  1624.       TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
  1625.  
  1626.       /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
  1627.      correspondence in any binding_level.  This is ok since the
  1628.      DECL_NESTED_TYPENAME is just a convenience identifier whose
  1629.      IDENTIFIER_TYPE_VALUE will remain constant from now on.  */
  1630.       SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
  1631.     }
  1632.   else
  1633.     DECL_NESTED_TYPENAME (decl) = name;
  1634. }
  1635.  
  1636. /* Pop off extraneous binding levels left over due to syntax errors.  */
  1637. void
  1638. pop_everything ()
  1639. {
  1640. #ifdef DEBUG_CP_BINDING_LEVELS
  1641.   fprintf (stderr, "XXX entering pop_everything ()\n");
  1642. #endif
  1643.   while (current_binding_level != global_binding_level
  1644.      && ! current_binding_level->pseudo_global)
  1645.     {
  1646.       if (class_binding_level)
  1647.     pop_nested_class (1);
  1648.       else
  1649.     poplevel (0, 0, 0);
  1650.     }
  1651. #ifdef DEBUG_CP_BINDING_LEVELS
  1652.   fprintf (stderr, "XXX leaving pop_everything ()\n");
  1653. #endif
  1654. }
  1655.  
  1656. #if 0 /* not yet, should get fixed properly later */
  1657. /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
  1658.    Other routines shouldn't use build_decl directly; they'll produce
  1659.    incorrect results with `-g' unless they duplicate this code.
  1660.  
  1661.    This is currently needed mainly for dbxout.c, but we can make
  1662.    use of it in method.c later as well.  */
  1663. tree
  1664. make_type_decl (name, type)
  1665.      tree name, type;
  1666. {
  1667.   tree decl, id;
  1668.   decl = build_decl (TYPE_DECL, name, type);
  1669.   if (TYPE_NAME (type) == name)
  1670.     /* Class/union/enum definition, or a redundant typedef for same.  */
  1671.     {
  1672.       id = get_identifier (build_overload_name (type, 1, 1));
  1673.       DECL_ASSEMBLER_NAME (decl) = id;
  1674.     }
  1675.   else if (TYPE_NAME (type) != NULL_TREE)
  1676.     /* Explicit typedef, or implicit typedef for template expansion.  */
  1677.     DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
  1678.   else
  1679.     {
  1680.       /* XXX: Typedef for unnamed struct; some other situations.
  1681.      TYPE_NAME is null; what's right here?  */
  1682.     }
  1683.   return decl;
  1684. }
  1685. #endif
  1686.  
  1687. /* Push a tag name NAME for struct/class/union/enum type TYPE.
  1688.    Normally put into into the inner-most non-tag-tranparent scope,
  1689.    but if GLOBALIZE is true, put it in the inner-most non-class scope.
  1690.    The latter is needed for implicit declarations. */
  1691.  
  1692. void
  1693. pushtag (name, type, globalize)
  1694.      tree name, type;
  1695.      int globalize;
  1696. {
  1697.   register struct binding_level *b;
  1698.   tree context = 0;
  1699.   tree c_decl = 0;
  1700.  
  1701.   b = inner_binding_level;
  1702.   while (b->tag_transparent
  1703.      || (globalize && b->parm_flag == 2))
  1704.     b = b->level_chain;
  1705.  
  1706.   if (b == global_binding_level)
  1707.     b->tags = perm_tree_cons (name, type, b->tags);
  1708.   else
  1709.     b->tags = saveable_tree_cons (name, type, b->tags);
  1710.  
  1711.   if (name)
  1712.     {
  1713.       context = type ? TYPE_CONTEXT (type) : NULL_TREE;
  1714.       if (! context && ! globalize)
  1715.         context = current_scope ();
  1716.       if (context)
  1717.     c_decl = TREE_CODE (context) == FUNCTION_DECL
  1718.       ? context : TYPE_NAME (context);
  1719.  
  1720.       /* Record the identifier as the type's name if it has none.  */
  1721.       if (TYPE_NAME (type) == NULL_TREE)
  1722.         TYPE_NAME (type) = name;
  1723.       
  1724.       /* Do C++ gratuitous typedefing.  */
  1725.       if (IDENTIFIER_TYPE_VALUE (name) != type
  1726.       && (TREE_CODE (type) != RECORD_TYPE
  1727.           || b->parm_flag != 2
  1728.           || !CLASSTYPE_DECLARED_EXCEPTION (type)))
  1729.         {
  1730.           register tree d;
  1731.       int newdecl = 0;
  1732.       
  1733.       if (b->parm_flag != 2
  1734.           || TYPE_SIZE (current_class_type) != NULL_TREE)
  1735.         {
  1736.           d = lookup_nested_type (type, c_decl);
  1737.  
  1738.           if (d == NULL_TREE)
  1739.         {
  1740.           newdecl = 1;
  1741. #if 0 /* not yet, should get fixed properly later */
  1742.           d = make_type_decl (name, type);
  1743. #else
  1744.           d = build_decl (TYPE_DECL, name, type);
  1745. #endif
  1746. #ifdef DWARF_DEBUGGING_INFO
  1747.           if (write_symbols == DWARF_DEBUG)
  1748.             {
  1749.               /* Mark the TYPE_DECL node we created just above as an
  1750.              gratuitous one.  We need to do this so that dwarfout.c
  1751.              will understand that it is not supposed to output a
  1752.              TAG_typedef DIE  for it. */
  1753.               DECL_IGNORED_P (d) = 1;
  1754.             }
  1755. #endif /* DWARF_DEBUGGING_INFO */
  1756.           set_identifier_type_value_with_scope (name, type, b);
  1757.         }
  1758.           else
  1759.         d = TYPE_NAME (d);
  1760.  
  1761.           /* If it is anonymous, then we are called from pushdecl,
  1762.          and we don't want to infinitely recurse.  Also, if the
  1763.          name is already in scope, we don't want to push it
  1764.          again--pushdecl is only for pushing new decls.  */
  1765.           if (! ANON_AGGRNAME_P (name)
  1766.           && TYPE_NAME (type)
  1767.           && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
  1768.               || lookup_name (name, 1) != TYPE_NAME (type)))
  1769.         {
  1770.           if (b->parm_flag == 2)
  1771.             d = pushdecl_class_level (d);
  1772.           else
  1773.             d = pushdecl_with_scope (d, b);
  1774.         }
  1775.         }
  1776.       else
  1777.         {
  1778.           /* Make nested declarations go into class-level scope.  */
  1779.           newdecl = 1;
  1780.           d = build_decl (TYPE_DECL, name, type);
  1781. #ifdef DWARF_DEBUGGING_INFO
  1782.           if (write_symbols == DWARF_DEBUG)
  1783.         {
  1784.           /* Mark the TYPE_DECL node we created just above as an
  1785.              gratuitous one.  We need to do this so that dwarfout.c
  1786.              will understand that it is not supposed to output a
  1787.              TAG_typedef DIE  for it. */
  1788.           DECL_IGNORED_P (d) = 1;
  1789.         }
  1790. #endif /* DWARF_DEBUGGING_INFO */
  1791.           /* Make sure we're in this type's scope when we push the
  1792.          decl for a template, otherwise class_binding_level will
  1793.          be NULL and we'll end up dying inside of
  1794.          push_class_level_binding.  */
  1795.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  1796.         pushclass (type, 0);
  1797.           d = pushdecl_class_level (d);
  1798.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  1799.         popclass (0);
  1800.         }
  1801.       if (write_symbols != DWARF_DEBUG)
  1802.         {
  1803.           if (ANON_AGGRNAME_P (name))
  1804.         DECL_IGNORED_P (d) = 1;
  1805.         }
  1806.       TYPE_NAME (type) = d;
  1807.  
  1808.       if (context == NULL_TREE)
  1809.         /* Non-nested class.  */
  1810.         DECL_NESTED_TYPENAME (d) = name;
  1811.       else if (context && TREE_CODE (context) == FUNCTION_DECL)
  1812.         {
  1813.           /* Function-nested class.  */
  1814.           set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
  1815.                    name, type);
  1816.           /* This builds the links for classes nested in fn scope.  */
  1817.           DECL_CONTEXT (d) = context;
  1818.         }
  1819. /*        else if (TYPE_SIZE (current_class_type) == NULL_TREE)
  1820. */
  1821.       else if (context && IS_AGGR_TYPE (context))
  1822.         {
  1823.           /* Class-nested class.  */
  1824.           set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
  1825.                    name, type);
  1826.           /* This builds the links for classes nested in type scope.  */
  1827.           DECL_CONTEXT (d) = context;
  1828.         }
  1829.       TYPE_CONTEXT (type) = DECL_CONTEXT (d);
  1830.       if (newdecl)
  1831.         DECL_ASSEMBLER_NAME (d)
  1832.           = get_identifier (build_overload_name (type, 1, 1));
  1833.         }
  1834.       if (b->parm_flag == 2)
  1835.     {
  1836.       TREE_NONLOCAL_FLAG (type) = 1;
  1837.       if (TYPE_SIZE (current_class_type) == NULL_TREE)
  1838.         CLASSTYPE_TAGS (current_class_type) = b->tags;
  1839.     }
  1840.     }
  1841.  
  1842.   if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  1843.     /* Use the canonical TYPE_DECL for this node.  */
  1844.     TYPE_STUB_DECL (type) = TYPE_NAME (type);
  1845.   else
  1846.     {
  1847.       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
  1848.      will be the tagged type we just added to the current
  1849.      binding level.  This fake NULL-named TYPE_DECL node helps
  1850.      dwarfout.c to know when it needs to output a
  1851.      representation of a tagged type, and it also gives us a
  1852.      convenient place to record the "scope start" address for
  1853.      the tagged type.  */
  1854.  
  1855. #if 0 /* not yet, should get fixed properly later */
  1856.       tree d = make_type_decl (NULL_TREE, type);
  1857. #else
  1858.       tree d = build_decl (TYPE_DECL, NULL_TREE, type);
  1859. #endif
  1860.       TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
  1861.     }
  1862. }
  1863.  
  1864. /* Counter used to create anonymous type names.  */
  1865. static int anon_cnt = 0;
  1866.  
  1867. /* Return an IDENTIFIER which can be used as a name for
  1868.    anonymous structs and unions.  */
  1869. tree
  1870. make_anon_name ()
  1871. {
  1872.   char buf[32];
  1873.  
  1874.   sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
  1875.   return get_identifier (buf);
  1876. }
  1877.  
  1878. /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
  1879.    This keeps dbxout from getting confused.  */
  1880. void
  1881. clear_anon_tags ()
  1882. {
  1883.   register struct binding_level *b;
  1884.   register tree tags;
  1885.   static int last_cnt = 0;
  1886.  
  1887.   /* Fast out if no new anon names were declared.  */
  1888.   if (last_cnt == anon_cnt)
  1889.     return;
  1890.  
  1891.   b = current_binding_level;
  1892.   while (b->tag_transparent)
  1893.     b = b->level_chain;
  1894.   tags = b->tags;
  1895.   while (tags)
  1896.     {
  1897.       /* A NULL purpose means we have already processed all tags
  1898.      from here to the end of the list.  */
  1899.       if (TREE_PURPOSE (tags) == NULL_TREE)
  1900.     break;
  1901.       if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
  1902.     TREE_PURPOSE (tags) = NULL_TREE;
  1903.       tags = TREE_CHAIN (tags);
  1904.     }
  1905.   last_cnt = anon_cnt;
  1906. }
  1907.  
  1908. /* Subroutine of duplicate_decls: return truthvalue of whether
  1909.    or not types of these decls match.
  1910.  
  1911.    For C++, we must compare the parameter list so that `int' can match
  1912.    `int&' in a parameter position, but `int&' is not confused with
  1913.    `const int&'.  */
  1914. static int
  1915. decls_match (newdecl, olddecl)
  1916.      tree newdecl, olddecl;
  1917. {
  1918.   int types_match;
  1919.  
  1920.   if (TREE_CODE (newdecl) == FUNCTION_DECL
  1921.       && TREE_CODE (olddecl) == FUNCTION_DECL)
  1922.     {
  1923.       tree f1 = TREE_TYPE (newdecl);
  1924.       tree f2 = TREE_TYPE (olddecl);
  1925.       tree p1 = TYPE_ARG_TYPES (f1);
  1926.       tree p2 = TYPE_ARG_TYPES (f2);
  1927.  
  1928.       /* When we parse a static member function definition,
  1929.      we put together a FUNCTION_DECL which thinks its type
  1930.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  1931.      proceed.  */
  1932.       if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
  1933.     revert_static_member_fn (&newdecl, &f1, &p1);
  1934.       else if (TREE_CODE (f2) == METHOD_TYPE
  1935.            && DECL_STATIC_FUNCTION_P (newdecl))
  1936.     revert_static_member_fn (&olddecl, &f2, &p2);
  1937.  
  1938.       /* Here we must take care of the case where new default
  1939.      parameters are specified.  Also, warn if an old
  1940.      declaration becomes ambiguous because default
  1941.      parameters may cause the two to be ambiguous.  */
  1942.       if (TREE_CODE (f1) != TREE_CODE (f2))
  1943.     {
  1944.       if (TREE_CODE (f1) == OFFSET_TYPE)
  1945.         cp_compiler_error ("`%D' redeclared as member function", newdecl);
  1946.       else
  1947.         cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
  1948.       return 0;
  1949.     }
  1950.  
  1951.       if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
  1952.     {
  1953.       if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
  1954.           && p2 == NULL_TREE)
  1955.         {
  1956.           types_match = self_promoting_args_p (p1);
  1957.           if (p1 == void_list_node)
  1958.         TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  1959.         }
  1960.       else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
  1961.            && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
  1962.         {
  1963.           types_match = self_promoting_args_p (p2);
  1964.           TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  1965.         }
  1966.       else
  1967.         types_match = compparms (p1, p2, 3);
  1968.     }
  1969.       else
  1970.     types_match = 0;
  1971.     }
  1972.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL
  1973.        && TREE_CODE (olddecl) == TEMPLATE_DECL)
  1974.     {
  1975.     tree newargs = DECL_TEMPLATE_PARMS (newdecl);
  1976.     tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
  1977.     int i, len = TREE_VEC_LENGTH (newargs);
  1978.  
  1979.     if (TREE_VEC_LENGTH (oldargs) != len)
  1980.       return 0;
  1981.     
  1982.     for (i = 0; i < len; i++)
  1983.       {
  1984.         tree newarg = TREE_VEC_ELT (newargs, i);
  1985.         tree oldarg = TREE_VEC_ELT (oldargs, i);
  1986.         if (TREE_CODE (newarg) != TREE_CODE (oldarg))
  1987.           return 0;
  1988.         else if (TREE_CODE (newarg) == IDENTIFIER_NODE)
  1989.           /* continue */;
  1990.         else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
  1991.           return 0;
  1992.       }
  1993.  
  1994.     if (DECL_TEMPLATE_IS_CLASS (newdecl)
  1995.         != DECL_TEMPLATE_IS_CLASS (olddecl))
  1996.       types_match = 0;
  1997.     else if (DECL_TEMPLATE_IS_CLASS (newdecl))
  1998.       types_match = 1;
  1999.     else
  2000.       types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
  2001.                      DECL_TEMPLATE_RESULT (newdecl));
  2002.     }
  2003.   else
  2004.     {
  2005.       if (TREE_TYPE (newdecl) == error_mark_node)
  2006.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  2007.       else if (TREE_TYPE (olddecl) == NULL_TREE)
  2008.     types_match = TREE_TYPE (newdecl) == NULL_TREE;
  2009.       else if (TREE_TYPE (newdecl) == NULL_TREE)
  2010.     types_match = 0;
  2011.       else
  2012.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  2013.     }
  2014.  
  2015.   return types_match;
  2016. }
  2017.  
  2018. /* If NEWDECL is `static' and an `extern' was seen previously,
  2019.    warn about it.  (OLDDECL may be NULL_TREE; NAME contains
  2020.    information about previous usage as an `extern'.)
  2021.  
  2022.    Note that this does not apply to the C++ case of declaring
  2023.    a variable `extern const' and then later `const'.
  2024.  
  2025.    Don't complain if -traditional, since traditional compilers
  2026.    don't complain.
  2027.  
  2028.    Don't complain about built-in functions, since they are beyond
  2029.    the user's control.  */
  2030.  
  2031. static void
  2032. warn_extern_redeclared_static (newdecl, olddecl)
  2033.      tree newdecl, olddecl;
  2034. {
  2035.   tree name;
  2036.  
  2037.   static char *explicit_extern_static_warning
  2038.     = "`%D' was declared `extern' and later `static'";
  2039.   static char *implicit_extern_static_warning
  2040.     = "`%D' was declared implicitly `extern' and later `static'";
  2041.  
  2042.   if (flag_traditional
  2043.       || TREE_CODE (newdecl) == TYPE_DECL
  2044.       || (! warn_extern_inline
  2045.       && DECL_INLINE (newdecl)))
  2046.     return;
  2047.  
  2048.   name = DECL_ASSEMBLER_NAME (newdecl);
  2049.   if (TREE_PUBLIC (name) && ! TREE_PUBLIC (newdecl))
  2050.     {
  2051.       /* It's okay to redeclare an ANSI built-in function as static,
  2052.      or to declare a non-ANSI built-in function as anything.  */
  2053.       if (! (TREE_CODE (newdecl) == FUNCTION_DECL
  2054.          && olddecl != NULL_TREE
  2055.          && TREE_CODE (olddecl) == FUNCTION_DECL
  2056.          && (DECL_BUILT_IN (olddecl)
  2057.          || DECL_BUILT_IN_NONANSI (olddecl))))
  2058.     {
  2059.       cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
  2060.               ? implicit_extern_static_warning
  2061.               : explicit_extern_static_warning, newdecl);
  2062.       if (olddecl != NULL_TREE)
  2063.         cp_warning_at ("previous declaration of `%D'", olddecl);
  2064.     }
  2065.     }
  2066. }
  2067.  
  2068. /* Handle when a new declaration NEWDECL has the same name as an old
  2069.    one OLDDECL in the same binding contour.  Prints an error message
  2070.    if appropriate.
  2071.  
  2072.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  2073.    Otherwise, return 0.  */
  2074.  
  2075. int
  2076. duplicate_decls (newdecl, olddecl)
  2077.      register tree newdecl, olddecl;
  2078. {
  2079.   extern struct obstack permanent_obstack;
  2080.   unsigned olddecl_uid = DECL_UID (olddecl);
  2081.   int olddecl_friend = 0, types_match = 0;
  2082.   int new_defines_function;
  2083.   tree previous_c_decl = NULL_TREE;
  2084.  
  2085.   types_match = decls_match (newdecl, olddecl);
  2086.  
  2087.   if (TREE_CODE (olddecl) != TREE_LIST)
  2088.     olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
  2089.  
  2090.   /* If either the type of the new decl or the type of the old decl is an
  2091.      error_mark_node, then that implies that we have already issued an
  2092.      error (earlier) for some bogus type specification, and in that case,
  2093.      it is rather pointless to harass the user with yet more error message
  2094.      about the same declaration, so well just pretent the types match here.  */
  2095.   if ((TREE_TYPE (newdecl)
  2096.        && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
  2097.       || (TREE_TYPE (olddecl)
  2098.       && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
  2099.     types_match = 1;
  2100.  
  2101.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  2102.       && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
  2103.     /* If -traditional, avoid error for redeclaring fcn
  2104.        after implicit decl.  */
  2105.     ;
  2106.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2107.        && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
  2108.     {
  2109.       /* If you declare a built-in or predefined function name as static,
  2110.      the old definition is overridden, but optionally warn this was a
  2111.      bad choice of name.  Ditto for overloads.  */
  2112.       if (! TREE_PUBLIC (newdecl)
  2113.       || (TREE_CODE (newdecl) == FUNCTION_DECL
  2114.           && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
  2115.     {
  2116.       if (warn_shadow)
  2117.         cp_warning ("shadowing %s function `%#D'",
  2118.             DECL_BUILT_IN (olddecl) ? "built-in" : "library",
  2119.             olddecl);
  2120.       /* Discard the old built-in function.  */
  2121.       return 0;
  2122.     }
  2123.       else if (! types_match)
  2124.     {
  2125.       if (TREE_CODE (newdecl) != FUNCTION_DECL)
  2126.         {
  2127.           /* If the built-in is not ansi, then programs can override
  2128.          it even globally without an error.  */
  2129.           if (! DECL_BUILT_IN (olddecl))
  2130.         cp_warning ("library function `%#D' redeclared as non-function `%#D'",
  2131.                 olddecl, newdecl);
  2132.           else
  2133.         {
  2134.           cp_error ("declaration of `%#D'", newdecl);
  2135.           cp_error ("conflicts with built-in declaration `%#D'",
  2136.                 olddecl);
  2137.         }
  2138.           return 0;
  2139.         }
  2140.  
  2141.       cp_warning ("declaration of `%#D'", newdecl);
  2142.       cp_warning ("conflicts with built-in declaration `%#D'",
  2143.               olddecl);
  2144.     }
  2145.     }
  2146.   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  2147.     {
  2148.       if ((TREE_CODE (newdecl) == FUNCTION_DECL
  2149.        && TREE_CODE (olddecl) == TEMPLATE_DECL
  2150.        && ! DECL_TEMPLATE_IS_CLASS (olddecl))
  2151.       || (TREE_CODE (olddecl) == FUNCTION_DECL
  2152.           && TREE_CODE (newdecl) == TEMPLATE_DECL
  2153.           && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
  2154.     return 0;
  2155.       
  2156.       cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
  2157.       if (TREE_CODE (olddecl) == TREE_LIST)
  2158.     olddecl = TREE_VALUE (olddecl);
  2159.       cp_error_at ("previous declaration of `%#D'", olddecl);
  2160.  
  2161.       /* New decl is completely inconsistent with the old one =>
  2162.      tell caller to replace the old one.  */
  2163.  
  2164.       return 0;
  2165.     }
  2166.   else if (!types_match)
  2167.     {
  2168.       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2169.     {
  2170.       /* The name of a class template may not be declared to refer to
  2171.          any other template, class, function, object, namespace, value,
  2172.          or type in the same scope. */
  2173.       if (DECL_TEMPLATE_IS_CLASS (olddecl)
  2174.           || DECL_TEMPLATE_IS_CLASS (newdecl))
  2175.         {
  2176.           cp_error ("declaration of template `%#D'", newdecl);
  2177.           cp_error_at ("conflicts with previous declaration `%#D'",
  2178.                olddecl);
  2179.         }
  2180.       return 0;
  2181.     }
  2182.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2183.     {
  2184.       if (DECL_LANGUAGE (newdecl) == lang_c
  2185.           && DECL_LANGUAGE (olddecl) == lang_c)
  2186.         {
  2187.           cp_error ("declaration of C function `%#D' conflicts with",
  2188.             newdecl);
  2189.           cp_error_at ("previous declaration `%#D' here", olddecl);
  2190.         }
  2191.  
  2192.       if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
  2193.              TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2))
  2194.         {
  2195.           cp_error ("new declaration `%#D'", newdecl);
  2196.           cp_error_at ("ambiguates old declaration `%#D'", olddecl);
  2197.         }
  2198.       else
  2199.         return 0;
  2200.     }
  2201.  
  2202.       /* Already complained about this, so don't do so again.  */
  2203.       else if (current_class_type == NULL_TREE
  2204.       || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  2205.     {
  2206.       /* Since we're doing this before finish_struct can set the
  2207.          line number on NEWDECL, we just do a regular error here.  */
  2208.       if (DECL_SOURCE_LINE (newdecl) == 0)
  2209.         cp_error ("conflicting types for `%#D'", newdecl);
  2210.       else
  2211.         cp_error_at ("conflicting types for `%#D'", newdecl);
  2212.       cp_error_at ("previous declaration as `%#D'", olddecl);
  2213.     }
  2214.     }
  2215.   else
  2216.     {
  2217.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  2218.       if (errmsg)
  2219.     {
  2220.       cp_error (errmsg, newdecl);
  2221.       if (DECL_NAME (olddecl) != NULL_TREE)
  2222.         cp_error_at ((DECL_INITIAL (olddecl)
  2223.               && current_binding_level == global_binding_level)
  2224.              ? "`%#D' previously defined here"
  2225.              : "`%#D' previously declared here", olddecl);
  2226.     }
  2227.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2228.            && DECL_INITIAL (olddecl) != NULL_TREE
  2229.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
  2230.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
  2231.     {
  2232.       /* Prototype decl follows defn w/o prototype.  */
  2233.       cp_warning_at ("prototype for `%#D'", newdecl);
  2234.       cp_warning_at ("follows non-prototype definition here", olddecl);
  2235.     }
  2236.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2237.            && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
  2238.     {
  2239.       /* extern "C" int foo ();
  2240.          int foo () { bar (); }
  2241.          is OK.  */
  2242.       if (current_lang_stack == current_lang_base)
  2243.         DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2244.       else
  2245.         {
  2246.           cp_error_at ("previous declaration of `%#D' with %L linkage",
  2247.                olddecl, DECL_LANGUAGE (olddecl));
  2248.           cp_error ("conflicts with new declaration with %L linkage",
  2249.             DECL_LANGUAGE (newdecl));
  2250.         }
  2251.     }
  2252.  
  2253.       /* These bits are logically part of the type.  */
  2254.       if (pedantic
  2255.       && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  2256.           || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
  2257.     cp_error_at ("type qualifiers for `%D' conflict with previous decl",
  2258.              newdecl);
  2259.     }
  2260.  
  2261.   /* If new decl is `static' and an `extern' was seen previously,
  2262.      warn about it.  */
  2263.   warn_extern_redeclared_static (newdecl, olddecl);
  2264.  
  2265.   /* We have committed to returning 1 at this point. */
  2266.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2267.     {
  2268.       /* Now that functions must hold information normally held
  2269.      by field decls, there is extra work to do so that
  2270.      declaration information does not get destroyed during
  2271.      definition.  */
  2272.       if (DECL_VINDEX (olddecl))
  2273.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  2274.       if (DECL_CONTEXT (olddecl))
  2275.     DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
  2276.       if (DECL_CLASS_CONTEXT (olddecl))
  2277.     DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
  2278.       if (DECL_CHAIN (newdecl) == NULL_TREE)
  2279.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2280.       if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
  2281.     DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
  2282.       if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
  2283.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  2284.     }
  2285.  
  2286.   /* Deal with C++: must preserve virtual function table size.  */
  2287.   if (TREE_CODE (olddecl) == TYPE_DECL)
  2288.     {
  2289.       register tree newtype = TREE_TYPE (newdecl);
  2290.       register tree oldtype = TREE_TYPE (olddecl);
  2291.  
  2292.       if (newtype != error_mark_node && oldtype != error_mark_node
  2293.       && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
  2294.     {
  2295.       CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
  2296.       CLASSTYPE_FRIEND_CLASSES (newtype)
  2297.         = CLASSTYPE_FRIEND_CLASSES (oldtype);
  2298.     }
  2299. #if 0
  2300.       /* why assert here?  Just because debugging information is
  2301.      messed up? (mrs) */
  2302.       /* it happens on something like:
  2303.          typedef struct Thing {
  2304.                     Thing();
  2305.                 int     x;
  2306.         } Thing;
  2307.       */
  2308.       my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
  2309.               139);
  2310. #endif
  2311.     }
  2312.  
  2313.   /* Special handling ensues if new decl is a function definition.  */
  2314.   new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
  2315.               && DECL_INITIAL (newdecl) != NULL_TREE);
  2316.  
  2317.   /* Optionally warn about more than one declaration for the same name,
  2318.      but don't warn about a function declaration followed by a definition.  */
  2319.   if (warn_redundant_decls
  2320.       && ! DECL_ARTIFICIAL (olddecl)
  2321.       && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
  2322.       /* Don't warn about extern decl followed by (tentative) definition.  */
  2323.       && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
  2324.     {
  2325.       cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
  2326.       cp_warning ("previous declaration of `%D'", olddecl);
  2327.     }
  2328.  
  2329.   /* Copy all the DECL_... slots specified in the new decl
  2330.      except for any that we copy here from the old type.  */
  2331.  
  2332.   if (types_match)
  2333.     {
  2334.       /* Automatically handles default parameters.  */
  2335.       tree oldtype = TREE_TYPE (olddecl);
  2336.       /* Merge the data types specified in the two decls.  */
  2337.       tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  2338.  
  2339.       /* Make sure we put the new type in the same obstack as the old ones.
  2340.      If the old types are not both in the same obstack, use the permanent
  2341.      one.  */
  2342.       if (oldtype && TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
  2343.     push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
  2344.       else
  2345.     {
  2346.       push_obstacks_nochange ();
  2347.       end_temporary_allocation ();
  2348.     }
  2349.  
  2350.       if (TREE_CODE (newdecl) == VAR_DECL)
  2351.     DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
  2352.       /* Do this after calling `common_type' so that default
  2353.      parameters don't confuse us.  */
  2354.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  2355.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  2356.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  2357.     {
  2358.       tree ctype = NULL_TREE;
  2359.       ctype = DECL_CLASS_CONTEXT (newdecl);
  2360.       TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
  2361.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  2362.       TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
  2363.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  2364.  
  2365.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  2366.         {
  2367.           cp_error ("declaration of `%D' raises different exceptions...",
  2368.             newdecl);
  2369.           cp_error_at ("...from previous declaration here", olddecl);
  2370.         }
  2371.     }
  2372.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  2373.  
  2374.       /* Lay the type out, unless already done.  */
  2375.       if (oldtype != TREE_TYPE (newdecl))
  2376.     {
  2377.       if (TREE_TYPE (newdecl) != error_mark_node)
  2378.         layout_type (TREE_TYPE (newdecl));
  2379.       if (TREE_CODE (newdecl) != FUNCTION_DECL
  2380.           && TREE_CODE (newdecl) != TYPE_DECL
  2381.           && TREE_CODE (newdecl) != CONST_DECL
  2382.           && TREE_CODE (newdecl) != TEMPLATE_DECL)
  2383.         layout_decl (newdecl, 0);
  2384.     }
  2385.       else
  2386.     {
  2387.       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
  2388.       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
  2389.     }
  2390.  
  2391.       /* Merge the type qualifiers.  */
  2392.       if (TREE_READONLY (newdecl))
  2393.     TREE_READONLY (olddecl) = 1;
  2394.       if (TREE_THIS_VOLATILE (newdecl))
  2395.     TREE_THIS_VOLATILE (olddecl) = 1;
  2396.  
  2397.       /* Merge the initialization information.  */
  2398.       if (DECL_INITIAL (newdecl) == NULL_TREE
  2399.       && DECL_INITIAL (olddecl) != NULL_TREE)
  2400.     {
  2401.       DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2402.       DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
  2403.       DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
  2404.     }
  2405.  
  2406.       /* Merge the section attribute.
  2407.          We want to issue an error if the sections conflict but that must be
  2408.      done later in decl_attributes since we are called before attributes
  2409.      are assigned.  */
  2410.       if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
  2411.     DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
  2412.  
  2413.       /* Keep the old rtl since we can safely use it, unless it's the
  2414.      call to abort() used for abstract virtuals.  */
  2415.       if ((DECL_LANG_SPECIFIC (olddecl)
  2416.        && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2417.       || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
  2418.     DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2419.  
  2420.       pop_obstacks ();
  2421.     }
  2422.   /* If cannot merge, then use the new type and qualifiers,
  2423.      and don't preserve the old rtl.  */
  2424.   else
  2425.     {
  2426.       /* Clean out any memory we had of the old declaration.  */
  2427.       tree oldstatic = value_member (olddecl, static_aggregates);
  2428.       if (oldstatic)
  2429.     TREE_VALUE (oldstatic) = error_mark_node;
  2430.  
  2431.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  2432.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  2433.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  2434.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  2435.     }
  2436.  
  2437.   /* Merge the storage class information.  */
  2438.   if (DECL_EXTERNAL (newdecl))
  2439.     {
  2440.       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
  2441.       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
  2442.  
  2443.       if (TREE_CODE (newdecl) != FUNCTION_DECL)
  2444.     TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  2445.     }
  2446.   else
  2447.     {
  2448.       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
  2449.       /* A `const' which was not declared `extern' and is
  2450.      in static storage is invisible.  */
  2451.       if (TREE_CODE (newdecl) == VAR_DECL
  2452.       && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
  2453.       && ! DECL_THIS_EXTERN (newdecl))
  2454.     TREE_PUBLIC (newdecl) = 0;
  2455.       else if (TREE_CODE (newdecl) != FUNCTION_DECL)
  2456.     TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  2457.     }
  2458.  
  2459.   /* For functions, static overrides non-static.  */
  2460.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2461.     {
  2462.       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
  2463.       /* This is since we don't automatically
  2464.      copy the attributes of NEWDECL into OLDDECL.  */
  2465.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  2466.       /* If this clears `static', clear it in the identifier too.  */
  2467.       if (! TREE_PUBLIC (olddecl))
  2468.     TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
  2469.     }
  2470.  
  2471.   /* If either decl says `inline', this fn is inline,
  2472.      unless its definition was passed already.  */
  2473.   if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
  2474.     DECL_INLINE (olddecl) = 1;
  2475.   DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
  2476.  
  2477.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2478.     {
  2479.       if (! types_match)
  2480.     {
  2481.       DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
  2482.       DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
  2483.       DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
  2484.       DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
  2485.       DECL_RTL (olddecl) = DECL_RTL (newdecl);
  2486.     }
  2487.       if (new_defines_function)
  2488.     /* If defining a function declared with other language
  2489.        linkage, use the previously declared language linkage.  */
  2490.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2491.       else
  2492.     {
  2493.       /* If redeclaring a builtin function, and not a definition,
  2494.          it stays built in.  */
  2495.       if (DECL_BUILT_IN (olddecl))
  2496.         {
  2497.           DECL_BUILT_IN (newdecl) = 1;
  2498.           DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
  2499.           /* If we're keeping the built-in definition, keep the rtl,
  2500.          regardless of declaration matches.  */
  2501.           DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2502.         }
  2503.       else
  2504.         DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  2505.  
  2506.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  2507.       if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
  2508.         /* Previously saved insns go together with
  2509.            the function's previous definition.  */
  2510.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2511.       /* Don't clear out the arguments if we're redefining a function.  */
  2512.       if (DECL_ARGUMENTS (olddecl))
  2513.         DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  2514.     }
  2515.     }
  2516.  
  2517.   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2518.     {
  2519.       if (DECL_TEMPLATE_INFO (olddecl)->length)
  2520.     DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
  2521.       DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
  2522.       DECL_TEMPLATE_INSTANTIATIONS (newdecl)
  2523.     = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
  2524.     }
  2525.   
  2526.   /* Now preserve various other info from the definition.  */
  2527.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  2528.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  2529.   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
  2530.  
  2531.   /* Don't really know how much of the language-specific
  2532.      values we should copy from old to new.  */
  2533.   if (DECL_LANG_SPECIFIC (olddecl))
  2534.     {
  2535.       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  2536.       DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
  2537.     }
  2538.  
  2539.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2540.     {
  2541.       int function_size;
  2542.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  2543.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  2544.  
  2545.       function_size = sizeof (struct tree_decl);
  2546.  
  2547.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  2548.          (char *) olddecl + sizeof (struct tree_common),
  2549.          function_size - sizeof (struct tree_common));
  2550.  
  2551.       /* Can we safely free the storage used by newdecl?  */
  2552.  
  2553. #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
  2554.           & ~ obstack_alignment_mask (&permanent_obstack))
  2555.  
  2556.       if ((char *)newdecl + ROUND (function_size)
  2557.       + ROUND (sizeof (struct lang_decl))
  2558.       == obstack_next_free (&permanent_obstack))
  2559.     {
  2560.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  2561.       DECL_LANG_SPECIFIC (olddecl) = ol;
  2562.       bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
  2563.  
  2564.       obstack_free (&permanent_obstack, newdecl);
  2565.     }
  2566.       else if (LANG_DECL_PERMANENT (ol))
  2567.     {
  2568.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  2569.         {
  2570.           /* Save these lang_decls that would otherwise be lost.  */
  2571.           extern tree free_lang_decl_chain;
  2572.           tree free_lang_decl = (tree) ol;
  2573.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  2574.           free_lang_decl_chain = free_lang_decl;
  2575.         }
  2576.       else
  2577.         {
  2578.           /* Storage leak.  */
  2579.         }
  2580.     }
  2581.     }
  2582.   else
  2583.     {
  2584.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  2585.          (char *) olddecl + sizeof (struct tree_common),
  2586.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  2587.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  2588.     }
  2589.  
  2590.   DECL_UID (olddecl) = olddecl_uid;
  2591.   if (olddecl_friend)
  2592.     DECL_FRIEND_P (olddecl) = 1;
  2593.  
  2594.   return 1;
  2595. }
  2596.  
  2597. /* Record a decl-node X as belonging to the current lexical scope.
  2598.    Check for errors (such as an incompatible declaration for the same
  2599.    name already seen in the same scope).
  2600.  
  2601.    Returns either X or an old decl for the same name.
  2602.    If an old decl is returned, it may have been smashed
  2603.    to agree with what X says.  */
  2604.  
  2605. tree
  2606. pushdecl (x)
  2607.      tree x;
  2608. {
  2609.   register tree t;
  2610. #if 0 /* not yet, should get fixed properly later */
  2611.   register tree name;
  2612. #else
  2613.   register tree name = DECL_ASSEMBLER_NAME (x);
  2614. #endif
  2615.   register struct binding_level *b = current_binding_level;
  2616.  
  2617. #if 0
  2618.   static int nglobals; int len;
  2619.  
  2620.   len = list_length (global_binding_level->names);
  2621.   if (len < nglobals)
  2622.     my_friendly_abort (8);
  2623.   else if (len > nglobals)
  2624.     nglobals = len;
  2625. #endif
  2626.  
  2627.   if (x != current_function_decl
  2628.       /* Don't change DECL_CONTEXT of virtual methods.  */
  2629.       && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
  2630.       && ! DECL_CONTEXT (x))
  2631.     DECL_CONTEXT (x) = current_function_decl;
  2632.   /* A local declaration for a function doesn't constitute nesting.  */
  2633.   if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
  2634.     DECL_CONTEXT (x) = 0;
  2635.  
  2636. #if 0 /* not yet, should get fixed properly later */
  2637.   /* For functions and class static data, we currently look up the encoded
  2638.      form of the name.  For types, we want the real name.  The former will
  2639.      probably be changed soon, according to MDT.  */
  2640.   if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
  2641.     name = DECL_ASSEMBLER_NAME (x);
  2642.   else
  2643.     name = DECL_NAME (x);
  2644. #else
  2645.   /* Type are looked up using the DECL_NAME, as that is what the rest of the
  2646.      compiler wants to use. */
  2647.   if (TREE_CODE (x) == TYPE_DECL)
  2648.     name = DECL_NAME (x);
  2649. #endif
  2650.  
  2651.   if (name)
  2652.     {
  2653.       char *file;
  2654.       int line;
  2655.  
  2656.       t = lookup_name_current_level (name);
  2657.       if (t == error_mark_node)
  2658.     {
  2659.       /* error_mark_node is 0 for a while during initialization!  */
  2660.       t = NULL_TREE;
  2661.       cp_error_at ("`%#D' used prior to declaration", x);
  2662.     }
  2663.  
  2664.       else if (t != NULL_TREE)
  2665.     {
  2666.       if (TREE_CODE (t) == PARM_DECL)
  2667.         {
  2668.           if (DECL_CONTEXT (t) == NULL_TREE)
  2669.         fatal ("parse errors have confused me too much");
  2670.         }
  2671.       file = DECL_SOURCE_FILE (t);
  2672.       line = DECL_SOURCE_LINE (t);
  2673.  
  2674.       if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
  2675.            || (TREE_CODE (x) == TEMPLATE_DECL
  2676.            && ! DECL_TEMPLATE_IS_CLASS (x)))
  2677.           && is_overloaded_fn (t))
  2678.         /* don't do anything just yet */;
  2679.       else if (TREE_CODE (t) != TREE_CODE (x))
  2680.         {
  2681.           if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
  2682.         {
  2683.           /* We do nothing special here, because C++ does such nasty
  2684.              things with TYPE_DECLs.  Instead, just let the TYPE_DECL
  2685.              get shadowed, and know that if we need to find a TYPE_DECL
  2686.              for a given name, we can look in the IDENTIFIER_TYPE_VALUE
  2687.              slot of the identifier.  */
  2688.           ;
  2689.         }
  2690.           else if (duplicate_decls (x, t))
  2691.         return t;
  2692.         }
  2693.       else if (duplicate_decls (x, t))
  2694.         {
  2695. #if 0
  2696.           /* This is turned off until I have time to do it right (bpk).  */
  2697.  
  2698.           /* Also warn if they did a prototype with `static' on it, but
  2699.          then later left the `static' off.  */
  2700.           if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
  2701.         {
  2702.           if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
  2703.             return t;
  2704.  
  2705.           if (extra_warnings)
  2706.             {
  2707.               cp_warning ("`static' missing from declaration of `%D'",
  2708.                   t);
  2709.               warning_with_file_and_line (file, line,
  2710.                           "previous declaration of `%s'",
  2711.                           decl_as_string (t, 0));
  2712.             }
  2713.  
  2714.           /* Now fix things so it'll do what they expect.  */
  2715.           if (current_function_decl)
  2716.             TREE_PUBLIC (current_function_decl) = 0;
  2717.         }
  2718.           /* Due to interference in memory reclamation (X may be
  2719.          obstack-deallocated at this point), we must guard against
  2720.          one really special case.  [jason: This should be handled
  2721.          by start_function]  */
  2722.           if (current_function_decl == x)
  2723.         current_function_decl = t;
  2724. #endif
  2725.           if (TREE_CODE (t) == TYPE_DECL)
  2726.         SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
  2727.  
  2728.           return t;
  2729.         }
  2730.     }
  2731.  
  2732.       if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
  2733.     {
  2734.       t = push_overloaded_decl (x, 1);
  2735.       if (t != x || DECL_LANGUAGE (x) == lang_c)
  2736.         return t;
  2737.     }
  2738.       else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
  2739.     return push_overloaded_decl (x, 0);
  2740.  
  2741.       /* If declaring a type as a typedef, and the type has no known
  2742.      typedef name, install this TYPE_DECL as its typedef name.  */
  2743.       if (TREE_CODE (x) == TYPE_DECL)
  2744.     {
  2745.       tree type = TREE_TYPE (x);
  2746.       tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
  2747.  
  2748.       if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
  2749.         {
  2750.           /* If these are different names, and we're at the global
  2751.          binding level, make two equivalent definitions.  */
  2752.               name = x;
  2753.               if (global_bindings_p ())
  2754.                 TYPE_NAME (type) = x;
  2755.         }
  2756.       else
  2757.         {
  2758.           tree tname = DECL_NAME (name);
  2759.  
  2760.           if (global_bindings_p () && ANON_AGGRNAME_P (tname))
  2761.         {
  2762.             /* do gratuitous C++ typedefing, and make sure that
  2763.                we access this type either through TREE_TYPE field
  2764.                or via the tags list.  */
  2765.           TYPE_NAME (TREE_TYPE (x)) = x;
  2766.           pushtag (tname, TREE_TYPE (x), 0);
  2767.         }
  2768.         }
  2769.       my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
  2770.  
  2771.       if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
  2772.         set_nested_typename (x, current_class_name,
  2773.                  DECL_NAME (name), type);
  2774.  
  2775.       if (type != error_mark_node
  2776.           && TYPE_NAME (type)
  2777.           && TYPE_IDENTIFIER (type))
  2778.             set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
  2779.     }
  2780.  
  2781.       /* Multiple external decls of the same identifier ought to match.
  2782.  
  2783.      We get warnings about inline functions where they are defined.
  2784.      We get warnings about other functions from push_overloaded_decl.
  2785.      
  2786.      Avoid duplicate warnings where they are used.  */
  2787.       if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
  2788.     {
  2789.       tree decl;
  2790.  
  2791.       if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
  2792.           && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  2793.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  2794.         decl = IDENTIFIER_GLOBAL_VALUE (name);
  2795.       else
  2796.         decl = NULL_TREE;
  2797.  
  2798.       if (decl
  2799.           /* If different sort of thing, we already gave an error.  */
  2800.           && TREE_CODE (decl) == TREE_CODE (x)
  2801.           && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
  2802.         {
  2803.           cp_pedwarn ("type mismatch with previous external decl", x);
  2804.           cp_pedwarn_at ("previous external decl of `%#D'", decl);
  2805.         }
  2806.     }
  2807.  
  2808.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  2809.      take effect at top level no matter where they are.  */
  2810.       if (flag_traditional && DECL_EXTERNAL (x)
  2811.       && lookup_name (name, 0) == NULL_TREE)
  2812.     b = global_binding_level;
  2813.  
  2814.       /* This name is new in its binding level.
  2815.      Install the new declaration and return it.  */
  2816.       if (b == global_binding_level)
  2817.     {
  2818.       /* Install a global value.  */
  2819.  
  2820.       /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
  2821.          A `const' which was not declared `extern' is invisible.  */
  2822.       if (TREE_CODE (x) == VAR_DECL
  2823.           && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
  2824.         TREE_PUBLIC (x) = 0;
  2825.  
  2826.       /* If the first global decl has external linkage,
  2827.          warn if we later see static one.  */
  2828.       if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
  2829.         TREE_PUBLIC (name) = 1;
  2830.  
  2831.       /* Don't install a TYPE_DECL if we already have another
  2832.          sort of _DECL with that name.  */
  2833.       if (TREE_CODE (x) != TYPE_DECL
  2834.           || t == NULL_TREE
  2835.           || TREE_CODE (t) == TYPE_DECL)
  2836.         IDENTIFIER_GLOBAL_VALUE (name) = x;
  2837.  
  2838.       /* Don't forget if the function was used via an implicit decl.  */
  2839.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2840.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  2841.         TREE_USED (x) = 1;
  2842.  
  2843.       /* Don't forget if its address was taken in that way.  */
  2844.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2845.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  2846.         TREE_ADDRESSABLE (x) = 1;
  2847.  
  2848.       /* Warn about mismatches against previous implicit decl.  */
  2849.       if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
  2850.           /* If this real decl matches the implicit, don't complain.  */
  2851.           && ! (TREE_CODE (x) == FUNCTION_DECL
  2852.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  2853.         cp_warning
  2854.           ("`%D' was previously implicitly declared to return `int'", x);
  2855.  
  2856.       /* If new decl is `static' and an `extern' was seen previously,
  2857.          warn about it.  */
  2858.       if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
  2859.         warn_extern_redeclared_static (x, t);
  2860.     }
  2861.       else
  2862.     {
  2863.       /* Here to install a non-global value.  */
  2864.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  2865.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  2866.  
  2867.       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  2868.       IDENTIFIER_LOCAL_VALUE (name) = x;
  2869.  
  2870.       /* If this is a TYPE_DECL, push it into the type value slot.  */
  2871.       if (TREE_CODE (x) == TYPE_DECL)
  2872.         set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
  2873.  
  2874.       /* If this is an extern function declaration, see if we
  2875.          have a global definition or declaration for the function.  */
  2876.       if (oldlocal == NULL_TREE
  2877.           && DECL_EXTERNAL (x) && !DECL_INLINE (x)
  2878.           && oldglobal != NULL_TREE
  2879.           && TREE_CODE (x) == FUNCTION_DECL
  2880.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  2881.         {
  2882.           /* We have one.  Their types must agree.  */
  2883.           if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
  2884.         {
  2885.           cp_warning ("extern declaration of `%#D' doesn't match", x);
  2886.           cp_warning_at ("global declaration `%#D'", oldglobal);
  2887.         }
  2888.           else
  2889.         {
  2890.           /* Inner extern decl is inline if global one is.
  2891.              Copy enough to really inline it.  */
  2892.           if (DECL_INLINE (oldglobal))
  2893.             {
  2894.               DECL_INLINE (x) = DECL_INLINE (oldglobal);
  2895.               DECL_INITIAL (x) = (current_function_decl == oldglobal
  2896.                       ? NULL_TREE : DECL_INITIAL (oldglobal));
  2897.               DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
  2898.               DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
  2899.               DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
  2900.               DECL_RESULT (x) = DECL_RESULT (oldglobal);
  2901.               TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
  2902.               DECL_ABSTRACT_ORIGIN (x) = oldglobal;
  2903.             }
  2904.           /* Inner extern decl is built-in if global one is.  */
  2905.           if (DECL_BUILT_IN (oldglobal))
  2906.             {
  2907.               DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
  2908.               DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
  2909.             }
  2910.           /* Keep the arg types from a file-scope fcn defn.  */
  2911.           if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE
  2912.               && DECL_INITIAL (oldglobal)
  2913.               && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE)
  2914.             TREE_TYPE (x) = TREE_TYPE (oldglobal);
  2915.         }
  2916.         }
  2917.       /* If we have a local external declaration,
  2918.          and no file-scope declaration has yet been seen,
  2919.          then if we later have a file-scope decl it must not be static.  */
  2920.       if (oldlocal == NULL_TREE
  2921.           && oldglobal == NULL_TREE
  2922.           && DECL_EXTERNAL (x)
  2923.           && TREE_PUBLIC (x))
  2924.         {
  2925.           TREE_PUBLIC (name) = 1;
  2926.         }
  2927.  
  2928.       if (DECL_FROM_INLINE (x))
  2929.         /* Inline decls shadow nothing.  */;
  2930.  
  2931.       /* Warn if shadowing an argument at the top level of the body.  */
  2932.       else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
  2933.           && TREE_CODE (oldlocal) == PARM_DECL
  2934.           && TREE_CODE (x) != PARM_DECL)
  2935.         {
  2936.           /* Go to where the parms should be and see if we
  2937.          find them there.  */
  2938.           struct binding_level *b = current_binding_level->level_chain;
  2939.  
  2940.           if (cleanup_label)
  2941.         b = b->level_chain;
  2942.  
  2943.           /* ARM $8.3 */
  2944.           if (b->parm_flag == 1)
  2945.         cp_error ("declaration of `%#D' shadows a parameter", name);
  2946.         }
  2947.       /* Maybe warn if shadowing something else.  */
  2948.       else if (warn_shadow && !DECL_EXTERNAL (x)
  2949.            /* No shadow warnings for internally generated vars.  */
  2950.            && ! DECL_ARTIFICIAL (x)
  2951.            /* No shadow warnings for vars made for inlining.  */
  2952.            && ! DECL_FROM_INLINE (x))
  2953.         {
  2954.           char *warnstring = NULL;
  2955.  
  2956.           if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
  2957.         warnstring = "declaration of `%s' shadows a parameter";
  2958.           else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
  2959.                && !TREE_STATIC (name))
  2960.         warnstring = "declaration of `%s' shadows a member of `this'";
  2961.           else if (oldlocal != NULL_TREE)
  2962.         warnstring = "declaration of `%s' shadows previous local";
  2963.           else if (oldglobal != NULL_TREE)
  2964.         warnstring = "declaration of `%s' shadows global declaration";
  2965.  
  2966.           if (warnstring)
  2967.         warning (warnstring, IDENTIFIER_POINTER (name));
  2968.         }
  2969.  
  2970.       /* If storing a local value, there may already be one (inherited).
  2971.          If so, record it for restoration when this binding level ends.  */
  2972.       if (oldlocal != NULL_TREE)
  2973.         b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  2974.     }
  2975.  
  2976.       /* Keep count of variables in this level with incomplete type.  */
  2977.       if (TREE_CODE (x) != TEMPLATE_DECL
  2978.       && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
  2979.       && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
  2980.     {
  2981.       if (++b->n_incomplete == 0)
  2982.         error ("too many incomplete variables at this point");
  2983.     }
  2984.     }
  2985.  
  2986.   if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
  2987.     {
  2988.       if (current_class_name)
  2989.     {
  2990.       if (! TREE_MANGLED (name))
  2991.         set_nested_typename (x, current_class_name, DECL_NAME (x),
  2992.                  TREE_TYPE (x));
  2993.     }
  2994.     }
  2995.  
  2996.   /* Put decls on list in reverse order.
  2997.      We will reverse them later if necessary.  */
  2998.   TREE_CHAIN (x) = b->names;
  2999.   b->names = x;
  3000.   if (! (b != global_binding_level || TREE_PERMANENT (x)))
  3001.     my_friendly_abort (124);
  3002.  
  3003.   return x;
  3004. }
  3005.  
  3006. /* Same as pushdecl, but define X in binding-level LEVEL. */
  3007.  
  3008. static tree
  3009. pushdecl_with_scope (x, level)
  3010.      tree x;
  3011.      struct binding_level *level;
  3012. {
  3013.   register struct binding_level *b = current_binding_level;
  3014.  
  3015.   current_binding_level = level;
  3016.   x = pushdecl (x);
  3017.   current_binding_level = b;
  3018.   return x;
  3019. }
  3020.  
  3021. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  3022.    if appropriate.  */
  3023. tree
  3024. pushdecl_top_level (x)
  3025.      tree x;
  3026. {
  3027.   register struct binding_level *b = inner_binding_level;
  3028.   register tree t = pushdecl_with_scope (x, global_binding_level);
  3029.  
  3030.   /* Now, the type_shadowed stack may screw us.  Munge it so it does
  3031.      what we want.  */
  3032.   if (TREE_CODE (x) == TYPE_DECL)
  3033.     {
  3034.       tree name = DECL_NAME (x);
  3035.       tree newval;
  3036.       tree *ptr = (tree *)0;
  3037.       for (; b != global_binding_level; b = b->level_chain)
  3038.         {
  3039.           tree shadowed = b->type_shadowed;
  3040.           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
  3041.             if (TREE_PURPOSE (shadowed) == name)
  3042.               {
  3043.         ptr = &TREE_VALUE (shadowed);
  3044.         /* Can't break out of the loop here because sometimes
  3045.            a binding level will have duplicate bindings for
  3046.            PT names.  It's gross, but I haven't time to fix it.  */
  3047.               }
  3048.         }
  3049.       newval = TREE_TYPE (x);
  3050.       if (ptr == (tree *)0)
  3051.         {
  3052.           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
  3053.              up here if this is changed to an assertion.  --KR  */
  3054.       SET_IDENTIFIER_TYPE_VALUE (name, newval);
  3055.     }
  3056.       else
  3057.         {
  3058. #if 0
  3059.       /* Disabled this 11/10/92, since there are many cases which
  3060.          behave just fine when *ptr doesn't satisfy either of these.
  3061.          For example, nested classes declared as friends of their enclosing
  3062.          class will not meet this criteria.  (bpk) */
  3063.       my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
  3064. #endif
  3065.       *ptr = newval;
  3066.         }
  3067.     }
  3068.   return t;
  3069. }
  3070.  
  3071. /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
  3072.    if appropriate.  */
  3073. void
  3074. push_overloaded_decl_top_level (x, forget)
  3075.      tree x;
  3076.      int forget;
  3077. {
  3078.   struct binding_level *b = current_binding_level;
  3079.  
  3080.   current_binding_level = global_binding_level;
  3081.   push_overloaded_decl (x, forget);
  3082.   current_binding_level = b;
  3083. }
  3084.  
  3085. /* Make the declaration of X appear in CLASS scope.  */
  3086. tree
  3087. pushdecl_class_level (x)
  3088.      tree x;
  3089. {
  3090.   /* Don't use DECL_ASSEMBLER_NAME here!  Everything that looks in class
  3091.      scope looks for the pre-mangled name.  */
  3092.   register tree name = DECL_NAME (x);
  3093.  
  3094.   if (name)
  3095.     {
  3096.       if (TYPE_BEING_DEFINED (current_class_type))
  3097.     {
  3098.       /* Check for inconsistent use of this name in the class body.
  3099.          Types, enums, and static vars are checked here; other
  3100.          members are checked in finish_struct.  */
  3101.       tree icv = IDENTIFIER_CLASS_VALUE (name);
  3102.  
  3103.       if (icv
  3104.           /* Don't complain about inherited names.  */
  3105.           && id_in_current_class (name)
  3106.           /* Or shadowed tags.  */
  3107.           && !(TREE_CODE (icv) == TYPE_DECL
  3108.            && DECL_CONTEXT (icv) == current_class_type))
  3109.         {
  3110.           cp_error ("declaration of identifier `%D' as `%#D'", name, x);
  3111.           cp_error_at ("conflicts with previous use in class as `%#D'",
  3112.                icv);
  3113.         }
  3114.     }
  3115.  
  3116.       push_class_level_binding (name, x);
  3117.       if (TREE_CODE (x) == TYPE_DECL)
  3118.     {
  3119.       set_identifier_type_value (name, TREE_TYPE (x));
  3120.       if (!DECL_NESTED_TYPENAME (x))
  3121.         set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
  3122.     }
  3123.     }
  3124.   return x;
  3125. }
  3126.  
  3127. /* This function is used to push the mangled decls for nested types into
  3128.    the appropriate scope.  Previously pushdecl_top_level was used, but that
  3129.    is incorrect for members of local classes.  */
  3130. tree
  3131. pushdecl_nonclass_level (x)
  3132.      tree x;
  3133. {
  3134.   struct binding_level *b = current_binding_level;
  3135.  
  3136. #if 0
  3137.   /* Get out of class scope -- this isn't necessary, because class scope
  3138.      doesn't make it into current_binding_level.  */
  3139.   while (b->parm_flag == 2)
  3140.     b = b->level_chain;
  3141. #else
  3142.   my_friendly_assert (b->parm_flag != 2, 180);
  3143. #endif
  3144.  
  3145.   /* Get out of template binding levels */
  3146.   while (b->pseudo_global)
  3147.     b = b->level_chain;
  3148.  
  3149.   pushdecl_with_scope (x, b);
  3150. }
  3151.  
  3152. /* Make the declaration(s) of X appear in CLASS scope
  3153.    under the name NAME.  */
  3154. void
  3155. push_class_level_binding (name, x)
  3156.      tree name;
  3157.      tree x;
  3158. {
  3159.   maybe_push_cache_obstack ();
  3160.   class_binding_level->class_shadowed
  3161.       = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
  3162.            class_binding_level->class_shadowed);
  3163.   pop_obstacks ();
  3164.   IDENTIFIER_CLASS_VALUE (name) = x;
  3165.   obstack_ptr_grow (&decl_obstack, x);
  3166. }
  3167.  
  3168. /* Tell caller how to interpret a TREE_LIST which contains
  3169.    chains of FUNCTION_DECLS.  */
  3170. int
  3171. overloaded_globals_p (list)
  3172.      tree list;
  3173. {
  3174.   my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
  3175.  
  3176.   /* Don't commit caller to seeing them as globals.  */
  3177.   if (TREE_NONLOCAL_FLAG (list))
  3178.     return -1;
  3179.   /* Do commit caller to seeing them as globals.  */
  3180.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  3181.     return 1;
  3182.   /* Do commit caller to not seeing them as globals.  */
  3183.   return 0;
  3184. }
  3185.  
  3186. /* DECL is a FUNCTION_DECL which may have other definitions already in
  3187.    place.  We get around this by making the value of the identifier point
  3188.    to a list of all the things that want to be referenced by that name.  It
  3189.    is then up to the users of that name to decide what to do with that
  3190.    list.
  3191.  
  3192.    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
  3193.    slot.  It is dealt with the same way.
  3194.  
  3195.    The value returned may be a previous declaration if we guessed wrong
  3196.    about what language DECL should belong to (C or C++).  Otherwise,
  3197.    it's always DECL (and never something that's not a _DECL).  */
  3198. tree
  3199. push_overloaded_decl (decl, forgettable)
  3200.      tree decl;
  3201.      int forgettable;
  3202. {
  3203.   tree orig_name = DECL_NAME (decl);
  3204.   tree old;
  3205.   int doing_global = (global_bindings_p () || ! forgettable
  3206.               || flag_traditional || pseudo_global_level_p ());
  3207.  
  3208.   if (doing_global)
  3209.     {
  3210.       old = IDENTIFIER_GLOBAL_VALUE (orig_name);
  3211.       if (old && TREE_CODE (old) == FUNCTION_DECL
  3212.       && DECL_ARTIFICIAL (old)
  3213.       && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
  3214.     {
  3215.       if (duplicate_decls (decl, old))
  3216.         return old;
  3217.       old = NULL_TREE;
  3218.     }
  3219.     }
  3220.   else
  3221.     {
  3222.       old = IDENTIFIER_LOCAL_VALUE (orig_name);
  3223.  
  3224.       if (! purpose_member (orig_name, current_binding_level->shadowed))
  3225.     {
  3226.       current_binding_level->shadowed
  3227.         = tree_cons (orig_name, old, current_binding_level->shadowed);
  3228.       old = NULL_TREE;
  3229.     }
  3230.     }
  3231.  
  3232.   if (old)
  3233.     {
  3234. #if 0
  3235.       /* We cache the value of builtin functions as ADDR_EXPRs
  3236.      in the name space.  Convert it to some kind of _DECL after
  3237.      remembering what to forget.  */
  3238.       if (TREE_CODE (old) == ADDR_EXPR)
  3239.     old = TREE_OPERAND (old, 0);
  3240.       else
  3241. #endif
  3242.       if (TREE_CODE (old) == VAR_DECL)
  3243.     {
  3244.       cp_error_at ("previous non-function declaration `%#D'", old);
  3245.       cp_error ("conflicts with function declaration `%#D'", decl);
  3246.       return error_mark_node;
  3247.     }
  3248.       else if (TREE_CODE (old) == TYPE_DECL)
  3249.     {
  3250.       tree t = TREE_TYPE (old);
  3251.       if (IS_AGGR_TYPE (t) && warn_shadow)
  3252.         cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
  3253.       old = NULL_TREE;
  3254.     }
  3255.       else if (is_overloaded_fn (old))
  3256.         {
  3257.           tree tmp;
  3258.       
  3259.       for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
  3260.         if (decl == tmp || duplicate_decls (decl, tmp))
  3261.           return tmp;
  3262.     }
  3263.     }
  3264.  
  3265.   if (old || TREE_CODE (decl) == TEMPLATE_DECL)
  3266.     {
  3267.       if (old && is_overloaded_fn (old))
  3268.     DECL_CHAIN (decl) = get_first_fn (old);
  3269.       else
  3270.     DECL_CHAIN (decl) = NULL_TREE;
  3271.       old = tree_cons (orig_name, decl, NULL_TREE);
  3272.       TREE_TYPE (old) = unknown_type_node;
  3273.     }
  3274.   else
  3275.     /* orig_name is not ambiguous.  */
  3276.     old = decl;
  3277.  
  3278.   if (doing_global)
  3279.     IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
  3280.   else
  3281.     IDENTIFIER_LOCAL_VALUE (orig_name) = old;
  3282.  
  3283.   return decl;
  3284. }
  3285.  
  3286. /* Generate an implicit declaration for identifier FUNCTIONID
  3287.    as a function of type int ().  Print a warning if appropriate.  */
  3288.  
  3289. tree
  3290. implicitly_declare (functionid)
  3291.      tree functionid;
  3292. {
  3293.   register tree decl;
  3294.   int temp = allocation_temporary_p ();
  3295.  
  3296.   push_obstacks_nochange ();
  3297.  
  3298.   /* Save the decl permanently so we can warn if definition follows.
  3299.      In ANSI C, warn_implicit is usually false, so the saves little space.
  3300.      But in C++, it's usually true, hence the extra code.  */
  3301.   if (temp && (flag_traditional || !warn_implicit
  3302.            || current_binding_level == global_binding_level))
  3303.     end_temporary_allocation ();
  3304.  
  3305.   /* We used to reuse an old implicit decl here,
  3306.      but this loses with inline functions because it can clobber
  3307.      the saved decl chains.  */
  3308.   decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  3309.  
  3310.   DECL_EXTERNAL (decl) = 1;
  3311.   TREE_PUBLIC (decl) = 1;
  3312.  
  3313.   /* ANSI standard says implicit declarations are in the innermost block.
  3314.      So we record the decl in the standard fashion.
  3315.      If flag_traditional is set, pushdecl does it top-level.  */
  3316.   pushdecl (decl);
  3317.   rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
  3318.  
  3319.   if (warn_implicit
  3320.       /* Only one warning per identifier.  */
  3321.       && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
  3322.     {
  3323.       cp_pedwarn ("implicit declaration of function `%#D'", decl);
  3324.     }
  3325.  
  3326.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  3327.  
  3328.   pop_obstacks ();
  3329.  
  3330.   return decl;
  3331. }
  3332.  
  3333. /* Return zero if the declaration NEWDECL is valid
  3334.    when the declaration OLDDECL (assumed to be for the same name)
  3335.    has already been seen.
  3336.    Otherwise return an error message format string with a %s
  3337.    where the identifier should go.  */
  3338.  
  3339. static char *
  3340. redeclaration_error_message (newdecl, olddecl)
  3341.      tree newdecl, olddecl;
  3342. {
  3343.   if (TREE_CODE (newdecl) == TYPE_DECL)
  3344.     {
  3345.       /* Because C++ can put things into name space for free,
  3346.      constructs like "typedef struct foo { ... } foo"
  3347.      would look like an erroneous redeclaration.  */
  3348.       if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  3349.     return 0;
  3350.       else
  3351.     return "redefinition of `%#D'";
  3352.     }
  3353.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  3354.     {
  3355.       /* If this is a pure function, its olddecl will actually be
  3356.      the original initialization to `0' (which we force to call
  3357.      abort()).  Don't complain about redefinition in this case.  */
  3358.       if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
  3359.     return 0;
  3360.  
  3361.       /* Declarations of functions can insist on internal linkage
  3362.      but they can't be inconsistent with internal linkage,
  3363.      so there can be no error on that account.
  3364.      However defining the same name twice is no good.  */
  3365.       if (DECL_INITIAL (olddecl) != NULL_TREE
  3366.       && DECL_INITIAL (newdecl) != NULL_TREE
  3367.       /* However, defining once as extern inline and a second
  3368.          time in another way is ok.  */
  3369.       && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
  3370.            && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
  3371.     {
  3372.       if (DECL_NAME (olddecl) == NULL_TREE)
  3373.         return "`%#D' not declared in class";
  3374.       else
  3375.         return "redefinition of `%#D'";
  3376.     }
  3377.  
  3378.       {
  3379.     tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
  3380.     tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
  3381.  
  3382.     if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
  3383.       t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
  3384.     
  3385.     for (; t1; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  3386.       if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  3387.         return "duplicate default arguments given for `%#D'";
  3388.       }
  3389.       return 0;
  3390.     }
  3391.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  3392.     {
  3393.       if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
  3394.     return "redefinition of `%#D'";
  3395.       return 0;
  3396.     }
  3397.   else if (current_binding_level == global_binding_level)
  3398.     {
  3399.       /* Objects declared at top level:  */
  3400.       /* If at least one is a reference, it's ok.  */
  3401.       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
  3402.     return 0;
  3403.       /* Now we have two tentative defs, or one tentative and one real def.  */
  3404.       /* Insist that the linkage match.  */
  3405.       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
  3406.     return "conflicting declarations of `%#D'";
  3407.       /* Reject two definitions.  */
  3408.       return "redefinition of `%#D'";
  3409.     }
  3410.   else
  3411.     {
  3412.       /* Objects declared with block scope:  */
  3413.       /* Reject two definitions, and reject a definition
  3414.      together with an external reference.  */
  3415.       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
  3416.     return "redeclaration of `%#D'";
  3417.       return 0;
  3418.     }
  3419. }
  3420.  
  3421. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  3422.    Create one if none exists so far for the current function.
  3423.    This function is called for both label definitions and label references.  */
  3424.  
  3425. tree
  3426. lookup_label (id)
  3427.      tree id;
  3428. {
  3429.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  3430.  
  3431.   if (current_function_decl == NULL_TREE)
  3432.     {
  3433.       error ("label `%s' referenced outside of any function",
  3434.          IDENTIFIER_POINTER (id));
  3435.       return NULL_TREE;
  3436.     }
  3437.  
  3438.   if ((decl == NULL_TREE
  3439.       || DECL_SOURCE_LINE (decl) == 0)
  3440.       && (named_label_uses == NULL_TREE
  3441.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  3442.       || TREE_VALUE (named_label_uses) != decl))
  3443.     {
  3444.       named_label_uses
  3445.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  3446.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  3447.     }
  3448.  
  3449.   /* Use a label already defined or ref'd with this name.  */
  3450.   if (decl != NULL_TREE)
  3451.     {
  3452.       /* But not if it is inherited and wasn't declared to be inheritable.  */
  3453.       if (DECL_CONTEXT (decl) != current_function_decl
  3454.       && ! C_DECLARED_LABEL_FLAG (decl))
  3455.     return shadow_label (id);
  3456.       return decl;
  3457.     }
  3458.  
  3459.   decl = build_decl (LABEL_DECL, id, void_type_node);
  3460.  
  3461.   /* A label not explicitly declared must be local to where it's ref'd.  */
  3462.   DECL_CONTEXT (decl) = current_function_decl;
  3463.  
  3464.   DECL_MODE (decl) = VOIDmode;
  3465.  
  3466.   /* Say where one reference is to the label,
  3467.      for the sake of the error if it is not defined.  */
  3468.   DECL_SOURCE_LINE (decl) = lineno;
  3469.   DECL_SOURCE_FILE (decl) = input_filename;
  3470.  
  3471.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  3472.  
  3473.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  3474.   TREE_VALUE (named_label_uses) = decl;
  3475.  
  3476.   return decl;
  3477. }
  3478.  
  3479. /* Make a label named NAME in the current function,
  3480.    shadowing silently any that may be inherited from containing functions
  3481.    or containing scopes.
  3482.  
  3483.    Note that valid use, if the label being shadowed
  3484.    comes from another scope in the same function,
  3485.    requires calling declare_nonlocal_label right away.  */
  3486.  
  3487. tree
  3488. shadow_label (name)
  3489.      tree name;
  3490. {
  3491.   register tree decl = IDENTIFIER_LABEL_VALUE (name);
  3492.  
  3493.   if (decl != NULL_TREE)
  3494.     {
  3495.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3496.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3497.       SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
  3498.     }
  3499.  
  3500.   return lookup_label (name);
  3501. }
  3502.  
  3503. /* Define a label, specifying the location in the source file.
  3504.    Return the LABEL_DECL node for the label, if the definition is valid.
  3505.    Otherwise return 0.  */
  3506.  
  3507. tree
  3508. define_label (filename, line, name)
  3509.      char *filename;
  3510.      int line;
  3511.      tree name;
  3512. {
  3513.   tree decl = lookup_label (name);
  3514.  
  3515.   /* After labels, make any new cleanups go into their
  3516.      own new (temporary) binding contour.  */
  3517.   current_binding_level->more_cleanups_ok = 0;
  3518.  
  3519.   /* If label with this name is known from an outer context, shadow it.  */
  3520.   if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
  3521.     {
  3522.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3523.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3524.       decl = lookup_label (name);
  3525.     }
  3526.  
  3527.   if (DECL_INITIAL (decl) != NULL_TREE)
  3528.     {
  3529.       cp_error ("duplicate label `%D'", decl);
  3530.       return 0;
  3531.     }
  3532.   else
  3533.     {
  3534.       tree uses, prev;
  3535.  
  3536.       /* Mark label as having been defined.  */
  3537.       DECL_INITIAL (decl) = error_mark_node;
  3538.       /* Say where in the source.  */
  3539.       DECL_SOURCE_FILE (decl) = filename;
  3540.       DECL_SOURCE_LINE (decl) = line;
  3541.  
  3542.       for (prev = NULL_TREE, uses = named_label_uses;
  3543.        uses;
  3544.        prev = uses, uses = TREE_CHAIN (uses))
  3545.     if (TREE_VALUE (uses) == decl)
  3546.       {
  3547.         struct binding_level *b = current_binding_level;
  3548.         while (b)
  3549.           {
  3550.         tree new_decls = b->names;
  3551.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  3552.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  3553.         while (new_decls != old_decls)
  3554.           {
  3555.             if (TREE_CODE (new_decls) == VAR_DECL
  3556.             /* Don't complain about crossing initialization
  3557.                of internal entities.  They can't be accessed,
  3558.                and they should be cleaned up
  3559.                by the time we get to the label.  */
  3560.             && ! DECL_ARTIFICIAL (new_decls)
  3561.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  3562.                  && DECL_INITIAL (new_decls) != error_mark_node)
  3563.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  3564.               {
  3565.             if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
  3566.               cp_error ("invalid jump to label `%D'", decl);
  3567.             SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
  3568.             cp_error ("crosses initialization of `%D'", new_decls);
  3569.               }
  3570.             new_decls = TREE_CHAIN (new_decls);
  3571.           }
  3572.         if ((tree)b == TREE_TYPE (uses))
  3573.           break;
  3574.         b = b->level_chain;
  3575.           }
  3576.  
  3577.         if (prev)
  3578.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  3579.         else
  3580.           named_label_uses = TREE_CHAIN (uses);
  3581.       }
  3582.       current_function_return_value = NULL_TREE;
  3583.       return decl;
  3584.     }
  3585. }
  3586.  
  3587. /* Same, but for CASE labels.  If DECL is NULL_TREE, it's the default.  */
  3588. /* XXX Note decl is never actually used. (bpk) */
  3589. void
  3590. define_case_label (decl)
  3591.      tree decl;
  3592. {
  3593.   tree cleanup = last_cleanup_this_contour ();
  3594.   if (cleanup)
  3595.     {
  3596.       static int explained = 0;
  3597.       cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
  3598.       error ("where case label appears here");
  3599.       if (!explained)
  3600.     {
  3601.       error ("(enclose actions of previous case statements requiring");
  3602.       error ("destructors in their own binding contours.)");
  3603.       explained = 1;
  3604.     }
  3605.     }
  3606.  
  3607.   /* After labels, make any new cleanups go into their
  3608.      own new (temporary) binding contour.  */
  3609.  
  3610.   current_binding_level->more_cleanups_ok = 0;
  3611.   current_function_return_value = NULL_TREE;
  3612. }
  3613.  
  3614. /* Return the list of declarations of the current level.
  3615.    Note that this list is in reverse order unless/until
  3616.    you nreverse it; and when you do nreverse it, you must
  3617.    store the result back using `storedecls' or you will lose.  */
  3618.  
  3619. tree
  3620. getdecls ()
  3621. {
  3622.   return current_binding_level->names;
  3623. }
  3624.  
  3625. /* Return the list of type-tags (for structs, etc) of the current level.  */
  3626.  
  3627. tree
  3628. gettags ()
  3629. {
  3630.   return current_binding_level->tags;
  3631. }
  3632.  
  3633. /* Store the list of declarations of the current level.
  3634.    This is done for the parameter declarations of a function being defined,
  3635.    after they are modified in the light of any missing parameters.  */
  3636.  
  3637. static void
  3638. storedecls (decls)
  3639.      tree decls;
  3640. {
  3641.   current_binding_level->names = decls;
  3642. }
  3643.  
  3644. /* Similarly, store the list of tags of the current level.  */
  3645.  
  3646. static void
  3647. storetags (tags)
  3648.      tree tags;
  3649. {
  3650.   current_binding_level->tags = tags;
  3651. }
  3652.  
  3653. /* Given NAME, an IDENTIFIER_NODE,
  3654.    return the structure (or union or enum) definition for that name.
  3655.    Searches binding levels from BINDING_LEVEL up to the global level.
  3656.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  3657.    (but skips any tag-transparent contexts to find one that is
  3658.    meaningful for tags).
  3659.    FORM says which kind of type the caller wants;
  3660.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  3661.    If the wrong kind of type is found, and it's not a template, an error is
  3662.    reported.  */
  3663.  
  3664. static tree
  3665. lookup_tag (form, name, binding_level, thislevel_only)
  3666.      enum tree_code form;
  3667.      struct binding_level *binding_level;
  3668.      tree name;
  3669.      int thislevel_only;
  3670. {
  3671.   register struct binding_level *level;
  3672.  
  3673.   for (level = binding_level; level; level = level->level_chain)
  3674.     {
  3675.       register tree tail;
  3676.       if (ANON_AGGRNAME_P (name))
  3677.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3678.       {
  3679.         /* There's no need for error checking here, because
  3680.            anon names are unique throughout the compilation.  */
  3681.         if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
  3682.           return TREE_VALUE (tail);
  3683.       }
  3684.       else
  3685.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3686.       {
  3687.         if (TREE_PURPOSE (tail) == name)
  3688.           {
  3689.         enum tree_code code = TREE_CODE (TREE_VALUE (tail));
  3690.         /* Should tighten this up; it'll probably permit
  3691.            UNION_TYPE and a struct template, for example.  */
  3692.         if (code != form
  3693.             && !(form != ENUMERAL_TYPE
  3694.              && (code == TEMPLATE_DECL
  3695.                  || code == UNINSTANTIATED_P_TYPE)))
  3696.                
  3697.           {
  3698.             /* Definition isn't the kind we were looking for.  */
  3699.             cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
  3700.                   form);
  3701.           }
  3702.         return TREE_VALUE (tail);
  3703.           }
  3704.       }
  3705.       if (thislevel_only && ! level->tag_transparent)
  3706.     return NULL_TREE;
  3707.       if (current_class_type && level->level_chain == global_binding_level)
  3708.     {
  3709.       /* Try looking in this class's tags before heading into
  3710.          global binding level.  */
  3711.       tree context = current_class_type;
  3712.       while (context)
  3713.         {
  3714.           switch (TREE_CODE_CLASS (TREE_CODE (context)))
  3715.         {
  3716.         tree these_tags;
  3717.         case 't':
  3718.             these_tags = CLASSTYPE_TAGS (context);
  3719.             if (ANON_AGGRNAME_P (name))
  3720.               while (these_tags)
  3721.             {
  3722.               if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
  3723.                   == name)
  3724.                 return TREE_VALUE (tail);
  3725.               these_tags = TREE_CHAIN (these_tags);
  3726.             }
  3727.             else
  3728.               while (these_tags)
  3729.             {
  3730.               if (TREE_PURPOSE (these_tags) == name)
  3731.                 {
  3732.                   if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  3733.                 {
  3734.                   cp_error ("`%#D' redeclared as %C in class scope",
  3735.                         TREE_VALUE (tail), form);
  3736.                 }
  3737.                   return TREE_VALUE (tail);
  3738.                 }
  3739.               these_tags = TREE_CHAIN (these_tags);
  3740.             }
  3741.             /* If this type is not yet complete, then don't
  3742.                look at its context.  */
  3743.             if (TYPE_SIZE (context) == NULL_TREE)
  3744.               goto no_context;
  3745.             /* Go to next enclosing type, if any.  */
  3746.             context = DECL_CONTEXT (TYPE_NAME (context));
  3747.             break;
  3748.             case 'd':
  3749.             context = DECL_CONTEXT (context);
  3750.             break;
  3751.             default:
  3752.             my_friendly_abort (10);
  3753.         }
  3754.           continue;
  3755.           no_context:
  3756.           break;
  3757.         }
  3758.     }
  3759.     }
  3760.   return NULL_TREE;
  3761. }
  3762.  
  3763. void
  3764. set_current_level_tags_transparency (tags_transparent)
  3765.      int tags_transparent;
  3766. {
  3767.   current_binding_level->tag_transparent = tags_transparent;
  3768. }
  3769.  
  3770. /* Given a type, find the tag that was defined for it and return the tag name.
  3771.    Otherwise return 0.  However, the value can never be 0
  3772.    in the cases in which this is used.
  3773.  
  3774.    C++: If NAME is non-zero, this is the new name to install.  This is
  3775.    done when replacing anonymous tags with real tag names.  */
  3776.  
  3777. static tree
  3778. lookup_tag_reverse (type, name)
  3779.      tree type;
  3780.      tree name;
  3781. {
  3782.   register struct binding_level *level;
  3783.  
  3784.   for (level = current_binding_level; level; level = level->level_chain)
  3785.     {
  3786.       register tree tail;
  3787.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3788.     {
  3789.       if (TREE_VALUE (tail) == type)
  3790.         {
  3791.           if (name)
  3792.         TREE_PURPOSE (tail) = name;
  3793.           return TREE_PURPOSE (tail);
  3794.         }
  3795.     }
  3796.     }
  3797.   return NULL_TREE;
  3798. }
  3799.  
  3800. /* Given type TYPE which was not declared in C++ language context,
  3801.    attempt to find a name by which it is referred.  */
  3802. tree
  3803. typedecl_for_tag (tag)
  3804.      tree tag;
  3805. {
  3806.   struct binding_level *b = current_binding_level;
  3807.  
  3808.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  3809.     return TYPE_NAME (tag);
  3810.  
  3811.   while (b)
  3812.     {
  3813.       tree decls = b->names;
  3814.       while (decls)
  3815.     {
  3816.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  3817.         break;
  3818.       decls = TREE_CHAIN (decls);
  3819.     }
  3820.       if (decls)
  3821.     return decls;
  3822.       b = b->level_chain;
  3823.     }
  3824.   return NULL_TREE;
  3825. }
  3826.  
  3827. /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
  3828.    Return the type value, or NULL_TREE if not found.  */
  3829. static tree
  3830. lookup_nested_type (type, context)
  3831.      tree type;
  3832.      tree context;
  3833. {
  3834.   if (context == NULL_TREE)
  3835.     return NULL_TREE;
  3836.   while (context)
  3837.     {
  3838.       switch (TREE_CODE (context))
  3839.     {
  3840.     case TYPE_DECL:
  3841.       {
  3842.         tree ctype = TREE_TYPE (context);
  3843.         tree match = value_member (type, CLASSTYPE_TAGS (ctype));
  3844.         if (match)
  3845.           return TREE_VALUE (match);
  3846.         context = DECL_CONTEXT (context);
  3847.  
  3848.         /* When we have a nested class whose member functions have
  3849.            local types (e.g., a set of enums), we'll arrive here
  3850.            with the DECL_CONTEXT as the actual RECORD_TYPE node for
  3851.            the enclosing class.  Instead, we want to make sure we
  3852.            come back in here with the TYPE_DECL, not the RECORD_TYPE.  */
  3853.         if (context && TREE_CODE (context) == RECORD_TYPE)
  3854.           context = TREE_CHAIN (context);
  3855.       }
  3856.       break;
  3857.     case FUNCTION_DECL:
  3858.       return TYPE_IDENTIFIER (type) ?
  3859.         lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
  3860.       break;
  3861.     default:
  3862.       my_friendly_abort (12);
  3863.     }
  3864.     }
  3865.   return NULL_TREE;
  3866. }
  3867.  
  3868. /* Look up NAME in the current binding level and its superiors in the
  3869.    namespace of variables, functions and typedefs.  Return a ..._DECL
  3870.    node of some kind representing its definition if there is only one
  3871.    such declaration, or return a TREE_LIST with all the overloaded
  3872.    definitions if there are many, or return 0 if it is undefined.
  3873.  
  3874.    If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
  3875.    If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
  3876.    Otherwise we prefer non-TYPE_DECLs.  */
  3877.  
  3878. tree
  3879. lookup_name_real (name, prefer_type, nonclass)
  3880.      tree name;
  3881.      int prefer_type, nonclass;
  3882. {
  3883.   register tree val;
  3884.   int yylex = 0;
  3885.  
  3886.   if (prefer_type == -2)
  3887.     {
  3888.       extern int looking_for_typename;
  3889.  
  3890.       yylex = 1;
  3891.       prefer_type = looking_for_typename;
  3892.       
  3893.       if (got_scope != NULL_TREE)
  3894.     {
  3895.       if (got_scope == void_type_node)
  3896.         val = IDENTIFIER_GLOBAL_VALUE (name);
  3897.       else if (TREE_CODE (got_scope) == TEMPLATE_TYPE_PARM
  3898.            /* TFIXME -- don't do this for UPTs in new model.  */
  3899.            || TREE_CODE (got_scope) == UNINSTANTIATED_P_TYPE)
  3900.         {
  3901.           if (prefer_type > 0)
  3902.         val = create_nested_upt (got_scope, name);
  3903.           else
  3904.         val = NULL_TREE;
  3905.         }
  3906.       else if (! IS_AGGR_TYPE (got_scope))
  3907.         /* Someone else will give an error about this if needed. */
  3908.         val = NULL_TREE;
  3909.       else if (TYPE_BEING_DEFINED (got_scope))
  3910.         {
  3911.           val = IDENTIFIER_CLASS_VALUE (name);
  3912.           if (val && DECL_CONTEXT (val) != got_scope)
  3913.         {
  3914.           struct binding_level *b = class_binding_level;
  3915.           for (val = NULL_TREE; b; b = b->level_chain)
  3916.             {
  3917.               tree t = purpose_member (name, b->class_shadowed);
  3918.               if (t && TREE_VALUE (t)
  3919.               && DECL_CONTEXT (TREE_VALUE (t)) == got_scope)
  3920.             {
  3921.               val = TREE_VALUE (t);
  3922.               break;
  3923.             }
  3924.             }
  3925.         }
  3926.           if (val == NULL_TREE
  3927.           && CLASSTYPE_LOCAL_TYPEDECLS (got_scope))
  3928.         val = lookup_field (got_scope, name, 0, 1);
  3929.         }
  3930.       else if (got_scope == current_class_type)
  3931.         val = IDENTIFIER_CLASS_VALUE (name);
  3932.       else
  3933.         val = lookup_field (got_scope, name, 0, 0);
  3934.  
  3935.       goto done;
  3936.     }
  3937.     }
  3938.     
  3939.   if (current_binding_level != global_binding_level
  3940.       && IDENTIFIER_LOCAL_VALUE (name))
  3941.     val = IDENTIFIER_LOCAL_VALUE (name);
  3942.   /* In C++ class fields are between local and global scope,
  3943.      just before the global scope.  */
  3944.   else if (current_class_type && ! nonclass)
  3945.     {
  3946.       val = IDENTIFIER_CLASS_VALUE (name);
  3947.       if (val == NULL_TREE
  3948.       && TYPE_BEING_DEFINED (current_class_type)
  3949.       && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  3950.     /* Try to find values from base classes if we are presently
  3951.        defining a type.  We are presently only interested in
  3952.        TYPE_DECLs.  */
  3953.     val = lookup_field (current_class_type, name, 0, 1);
  3954.  
  3955.       /* yylex() calls this with -2, since we should never start digging for
  3956.      the nested name at the point where we haven't even, for example,
  3957.      created the COMPONENT_REF or anything like that.  */
  3958.       if (val == NULL_TREE)
  3959.     val = lookup_nested_field (name, ! yylex);
  3960.  
  3961.       if (val == NULL_TREE)
  3962.     val = IDENTIFIER_GLOBAL_VALUE (name);
  3963.     }
  3964.   else
  3965.     val = IDENTIFIER_GLOBAL_VALUE (name);
  3966.  
  3967.  done:
  3968.   if (val)
  3969.     {
  3970.       if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
  3971.       || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
  3972.     return val;
  3973.  
  3974.       if (IDENTIFIER_HAS_TYPE_VALUE (name))
  3975.     return TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
  3976.  
  3977.       if (TREE_TYPE (val) == error_mark_node)
  3978.     return error_mark_node;
  3979.     }
  3980.  
  3981.   return val;
  3982. }
  3983.  
  3984. tree
  3985. lookup_name_nonclass (name)
  3986.      tree name;
  3987. {
  3988.   return lookup_name_real (name, 0, 1);
  3989. }
  3990.  
  3991. tree
  3992. lookup_name (name, prefer_type)
  3993.      tree name;
  3994.      int prefer_type;
  3995. {
  3996.   return lookup_name_real (name, prefer_type, 0);
  3997. }
  3998.  
  3999. /* Similar to `lookup_name' but look only at current binding level.  */
  4000.  
  4001. tree
  4002. lookup_name_current_level (name)
  4003.      tree name;
  4004. {
  4005.   register tree t = NULL_TREE;
  4006.  
  4007.   if (current_binding_level == global_binding_level)
  4008.     {
  4009.       t = IDENTIFIER_GLOBAL_VALUE (name);
  4010.  
  4011.       /* extern "C" function() */
  4012.       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
  4013.     t = TREE_VALUE (t);
  4014.     }
  4015.   else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
  4016.     {
  4017.       struct binding_level *b = current_binding_level;
  4018.       while (1)
  4019.     {
  4020.       for (t = b->names; t; t = TREE_CHAIN (t))
  4021.         if (DECL_NAME (t) == name)
  4022.           goto out;
  4023.       if (b->keep == 2)
  4024.         b = b->level_chain;
  4025.       else
  4026.         break;
  4027.     }
  4028.     out:
  4029.       ;
  4030.     }
  4031.  
  4032.   return t;
  4033. }
  4034.  
  4035. /* Arrange for the user to get a source line number, even when the
  4036.    compiler is going down in flames, so that she at least has a
  4037.    chance of working around problems in the compiler.  We used to
  4038.    call error(), but that let the segmentation fault continue
  4039.    through; now, it's much more passive by asking them to send the
  4040.    maintainers mail about the problem.  */
  4041.  
  4042. static void
  4043. signal_catch (sig)
  4044.      int sig;
  4045. {
  4046.   signal (SIGSEGV, SIG_DFL);
  4047. #ifdef SIGIOT
  4048.   signal (SIGIOT, SIG_DFL);
  4049. #endif
  4050. #ifdef SIGILL
  4051.   signal (SIGILL, SIG_DFL);
  4052. #endif
  4053. #ifdef SIGABRT
  4054.   signal (SIGABRT, SIG_DFL);
  4055. #endif
  4056. #ifdef SIGBUS
  4057.   signal (SIGBUS, SIG_DFL);
  4058. #endif
  4059.   my_friendly_abort (0);
  4060. }
  4061.  
  4062. /* Array for holding types considered "built-in".  These types
  4063.    are output in the module in which `main' is defined.  */
  4064. static tree *builtin_type_tdescs_arr;
  4065. static int builtin_type_tdescs_len, builtin_type_tdescs_max;
  4066.  
  4067. /* Push the declarations of builtin types into the namespace.
  4068.    RID_INDEX, if < RID_MAX is the index of the builtin type
  4069.    in the array RID_POINTERS.  NAME is the name used when looking
  4070.    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
  4071.  
  4072. static void
  4073. record_builtin_type (rid_index, name, type)
  4074.      enum rid rid_index;
  4075.      char *name;
  4076.      tree type;
  4077. {
  4078.   tree rname = NULL_TREE, tname = NULL_TREE;
  4079.   tree tdecl;
  4080.  
  4081.   if ((int) rid_index < (int) RID_MAX)
  4082.     rname = ridpointers[(int) rid_index];
  4083.   if (name)
  4084.     tname = get_identifier (name);
  4085.  
  4086.   TYPE_BUILT_IN (type) = 1;
  4087.   
  4088.   if (tname)
  4089.     {
  4090. #if 0 /* not yet, should get fixed properly later */
  4091.       tdecl = pushdecl (make_type_decl (tname, type));
  4092. #else
  4093.       tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
  4094. #endif
  4095.       set_identifier_type_value (tname, NULL_TREE);
  4096.       if ((int) rid_index < (int) RID_MAX)
  4097.     IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
  4098.     }
  4099.   if (rname != NULL_TREE)
  4100.     {
  4101.       if (tname != NULL_TREE)
  4102.     {
  4103.       set_identifier_type_value (rname, NULL_TREE);
  4104.       IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
  4105.     }
  4106.       else
  4107.     {
  4108. #if 0 /* not yet, should get fixed properly later */
  4109.       tdecl = pushdecl (make_type_decl (rname, type));
  4110. #else
  4111.       tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
  4112. #endif
  4113.       set_identifier_type_value (rname, NULL_TREE);
  4114.     }
  4115.     }
  4116.  
  4117.   if (flag_dossier)
  4118.     {
  4119.       if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
  4120.     {
  4121.       builtin_type_tdescs_max *= 2;
  4122.       builtin_type_tdescs_arr
  4123.         = (tree *)xrealloc (builtin_type_tdescs_arr,
  4124.                 builtin_type_tdescs_max * sizeof (tree));
  4125.     }
  4126.       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
  4127.       if (TREE_CODE (type) != POINTER_TYPE)
  4128.     {
  4129.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4130.         = build_pointer_type (type);
  4131.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4132.         = build_pointer_type (build_type_variant (type, 1, 0));
  4133.     }
  4134.       if (TREE_CODE (type) != VOID_TYPE)
  4135.     {
  4136.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4137.         = build_reference_type (type);
  4138.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4139.         = build_reference_type (build_type_variant (type, 1, 0));
  4140.     }
  4141.     }
  4142. }
  4143.  
  4144. static void
  4145. output_builtin_tdesc_entries ()
  4146. {
  4147.   extern struct obstack permanent_obstack;
  4148.  
  4149.   /* If there's more than one main in this file, don't crash.  */
  4150.   if (builtin_type_tdescs_arr == 0)
  4151.     return;
  4152.  
  4153.   push_obstacks (&permanent_obstack, &permanent_obstack);
  4154.   while (builtin_type_tdescs_len > 0)
  4155.     {
  4156.       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
  4157.       tree tdesc = build_t_desc (type, 0);
  4158.       TREE_ASM_WRITTEN (tdesc) = 0;
  4159.       build_t_desc (type, 2);
  4160.     }
  4161.   free (builtin_type_tdescs_arr);
  4162.   builtin_type_tdescs_arr = 0;
  4163.   pop_obstacks ();
  4164. }
  4165.  
  4166. /* Push overloaded decl, in global scope, with one argument so it
  4167.    can be used as a callback from define_function.  */
  4168. static void
  4169. push_overloaded_decl_1 (x)
  4170.      tree x;
  4171. {
  4172.   push_overloaded_decl (x, 0);
  4173. }
  4174.  
  4175. /* Create the predefined scalar types of C,
  4176.    and some nodes representing standard constants (0, 1, (void *)0).
  4177.    Initialize the global binding level.
  4178.    Make definitions for built-in primitive functions.  */
  4179.  
  4180. void
  4181. init_decl_processing ()
  4182. {
  4183.   tree decl;
  4184.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  4185.   tree fields[20];
  4186.   /* Either char* or void*.  */
  4187.   tree traditional_ptr_type_node;
  4188.   /* Data type of memcpy.  */
  4189.   tree memcpy_ftype;
  4190. #if 0 /* Not yet.  */
  4191.   /* Data type of strncpy.  */
  4192.   tree strncpy_ftype;
  4193. #endif
  4194.   int wchar_type_size;
  4195.   tree temp;
  4196.   tree array_domain_type;
  4197.  
  4198.   /* Have to make these distinct before we try using them.  */
  4199.   lang_name_cplusplus = get_identifier ("C++");
  4200.   lang_name_c = get_identifier ("C");
  4201.  
  4202.   if (flag_ansi || pedantic)
  4203.     strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
  4204.  
  4205.   /* Initially, C.  */
  4206.   current_lang_name = lang_name_c;
  4207.  
  4208.   current_function_decl = NULL_TREE;
  4209.   named_labels = NULL_TREE;
  4210.   named_label_uses = NULL_TREE;
  4211.   current_binding_level = NULL_BINDING_LEVEL;
  4212.   free_binding_level = NULL_BINDING_LEVEL;
  4213.  
  4214.   /* Because most segmentation signals can be traced back into user
  4215.      code, catch them and at least give the user a chance of working
  4216.      around compiler bugs. */
  4217.   signal (SIGSEGV, signal_catch);
  4218.  
  4219.   /* We will also catch aborts in the back-end through signal_catch and
  4220.      give the user a chance to see where the error might be, and to defeat
  4221.      aborts in the back-end when there have been errors previously in their
  4222.      code. */
  4223. #ifdef SIGIOT
  4224.   signal (SIGIOT, signal_catch);
  4225. #endif
  4226. #ifdef SIGILL
  4227.   signal (SIGILL, signal_catch);
  4228. #endif
  4229. #ifdef SIGABRT
  4230.   signal (SIGABRT, signal_catch);
  4231. #endif
  4232. #ifdef SIGBUS
  4233.   signal (SIGBUS, signal_catch);
  4234. #endif
  4235.  
  4236.   gcc_obstack_init (&decl_obstack);
  4237.   if (flag_dossier)
  4238.     {
  4239.       builtin_type_tdescs_max = 100;
  4240.       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
  4241.     }
  4242.  
  4243.   /* Must lay these out before anything else gets laid out.  */
  4244.   error_mark_node = make_node (ERROR_MARK);
  4245.   TREE_PERMANENT (error_mark_node) = 1;
  4246.   TREE_TYPE (error_mark_node) = error_mark_node;
  4247.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  4248.   TREE_TYPE (error_mark_list) = error_mark_node;
  4249.  
  4250.   /* Make the binding_level structure for global names.  */
  4251.   pushlevel (0);
  4252.   global_binding_level = current_binding_level;
  4253.  
  4254.   this_identifier = get_identifier (THIS_NAME);
  4255.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  4256.   pfn_identifier = get_identifier (VTABLE_PFN_NAME);
  4257.   index_identifier = get_identifier (VTABLE_INDEX_NAME);
  4258.   delta_identifier = get_identifier (VTABLE_DELTA_NAME);
  4259.   delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
  4260.   pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
  4261.  
  4262.   /* Define `int' and `char' first so that dbx will output them first.  */
  4263.  
  4264.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  4265.   record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
  4266.  
  4267.   /* Define `char', which is like either `signed char' or `unsigned char'
  4268.      but not the same as either.  */
  4269.  
  4270.   char_type_node =
  4271.     (flag_signed_char
  4272.      ? make_signed_type (CHAR_TYPE_SIZE)
  4273.      : make_unsigned_type (CHAR_TYPE_SIZE));
  4274.   record_builtin_type (RID_CHAR, "char", char_type_node);
  4275.  
  4276.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  4277.   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
  4278.  
  4279.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  4280.   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
  4281.  
  4282.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  4283.   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
  4284.   record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
  4285.  
  4286.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  4287.   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
  4288.  
  4289.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  4290.   record_builtin_type (RID_MAX, "long long unsigned int",
  4291.                long_long_unsigned_type_node);
  4292.   record_builtin_type (RID_MAX, "long long unsigned",
  4293.                long_long_unsigned_type_node);
  4294.  
  4295.   /* `unsigned long' is the standard type for sizeof.
  4296.      Traditionally, use a signed type.
  4297.      Note that stddef.h uses `unsigned long',
  4298.      and this must agree, even of long and int are the same size.  */
  4299.   sizetype
  4300.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
  4301.   if (flag_traditional && TREE_UNSIGNED (sizetype))
  4302.     sizetype = signed_type (sizetype);
  4303.  
  4304.   ptrdiff_type_node
  4305.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
  4306.  
  4307.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  4308.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  4309.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  4310.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  4311.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  4312.   TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
  4313.   TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
  4314.  
  4315.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  4316.   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
  4317.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  4318.   record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
  4319.   record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
  4320.  
  4321.   /* Define both `signed char' and `unsigned char'.  */
  4322.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  4323.   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
  4324.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  4325.   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
  4326.  
  4327.   /* These are types that type_for_size and type_for_mode use.  */
  4328.   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
  4329.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
  4330.   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
  4331.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
  4332.   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
  4333.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
  4334.   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
  4335.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
  4336.   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
  4337.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
  4338.   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
  4339.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
  4340.   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
  4341.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
  4342.   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
  4343.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
  4344.  
  4345.   float_type_node = make_node (REAL_TYPE);
  4346.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  4347.   record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
  4348.   layout_type (float_type_node);
  4349.  
  4350.   double_type_node = make_node (REAL_TYPE);
  4351.   if (flag_short_double)
  4352.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  4353.   else
  4354.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  4355.   record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
  4356.   layout_type (double_type_node);
  4357.  
  4358.   long_double_type_node = make_node (REAL_TYPE);
  4359.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  4360.   record_builtin_type (RID_MAX, "long double", long_double_type_node);
  4361.   layout_type (long_double_type_node);
  4362.  
  4363.   integer_zero_node = build_int_2 (0, 0);
  4364.   TREE_TYPE (integer_zero_node) = integer_type_node;
  4365.   integer_one_node = build_int_2 (1, 0);
  4366.   TREE_TYPE (integer_one_node) = integer_type_node;
  4367.   integer_two_node = build_int_2 (2, 0);
  4368.   TREE_TYPE (integer_two_node) = integer_type_node;
  4369.   integer_three_node = build_int_2 (3, 0);
  4370.   TREE_TYPE (integer_three_node) = integer_type_node;
  4371.  
  4372.   bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  4373.   TREE_SET_CODE (bool_type_node, BOOLEAN_TYPE);
  4374.   record_builtin_type (RID_BOOL, "bool", bool_type_node);
  4375.   false_node = build_int_2 (0, 0);
  4376.   TREE_TYPE (false_node) = bool_type_node;
  4377.   true_node = build_int_2 (1, 0);
  4378.   TREE_TYPE (true_node) = bool_type_node;
  4379.  
  4380.   /* These are needed by stor-layout.c.  */
  4381.   size_zero_node = size_int (0);
  4382.   size_one_node = size_int (1);
  4383.  
  4384.   void_type_node = make_node (VOID_TYPE);
  4385.   record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
  4386.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  4387.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  4388.   TREE_PARMLIST (void_list_node) = 1;
  4389.  
  4390.   null_pointer_node = build_int_2 (0, 0);
  4391.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  4392.   layout_type (TREE_TYPE (null_pointer_node));
  4393.  
  4394.   /* Used for expressions that do nothing, but are not errors.  */
  4395.   void_zero_node = build_int_2 (0, 0);
  4396.   TREE_TYPE (void_zero_node) = void_type_node;
  4397.  
  4398.   string_type_node = build_pointer_type (char_type_node);
  4399.   const_string_type_node =
  4400.     build_pointer_type (build_type_variant (char_type_node, 1, 0));
  4401.   record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
  4402.  
  4403.   /* Make a type to be the domain of a few array types
  4404.      whose domains don't really matter.
  4405.      200 is small enough that it always fits in size_t
  4406.      and large enough that it can hold most function names for the
  4407.      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
  4408.   array_domain_type = build_index_type (build_int_2 (200, 0));
  4409.  
  4410.   /* make a type for arrays of characters.
  4411.      With luck nothing will ever really depend on the length of this
  4412.      array type.  */
  4413.   char_array_type_node
  4414.     = build_array_type (char_type_node, array_domain_type);
  4415.   /* Likewise for arrays of ints.  */
  4416.   int_array_type_node
  4417.     = build_array_type (integer_type_node, array_domain_type);
  4418.  
  4419.   /* This is just some anonymous class type.  Nobody should ever
  4420.      need to look inside this envelope.  */
  4421.   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
  4422.  
  4423.   default_function_type
  4424.     = build_function_type (integer_type_node, NULL_TREE);
  4425.   build_pointer_type (default_function_type);
  4426.  
  4427.   ptr_type_node = build_pointer_type (void_type_node);
  4428.   const_ptr_type_node =
  4429.     build_pointer_type (build_type_variant (void_type_node, 1, 0));
  4430.   record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
  4431.   endlink = void_list_node;
  4432.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  4433.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  4434.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  4435.  
  4436.   double_ftype_double
  4437.     = build_function_type (double_type_node, double_endlink);
  4438.  
  4439.   double_ftype_double_double
  4440.     = build_function_type (double_type_node,
  4441.                tree_cons (NULL_TREE, double_type_node,
  4442.                       double_endlink));
  4443.  
  4444.   int_ftype_int
  4445.     = build_function_type (integer_type_node, int_endlink);
  4446.  
  4447.   long_ftype_long
  4448.     = build_function_type (long_integer_type_node,
  4449.                tree_cons (NULL_TREE, long_integer_type_node,
  4450.                       endlink));
  4451.  
  4452.   void_ftype_ptr_ptr_int
  4453.     = build_function_type (void_type_node,
  4454.                tree_cons (NULL_TREE, ptr_type_node,
  4455.                       tree_cons (NULL_TREE, ptr_type_node,
  4456.                          int_endlink)));
  4457.  
  4458.   int_ftype_cptr_cptr_sizet
  4459.     = build_function_type (integer_type_node,
  4460.                tree_cons (NULL_TREE, const_ptr_type_node,
  4461.                       tree_cons (NULL_TREE, const_ptr_type_node,
  4462.                          tree_cons (NULL_TREE,
  4463.                                 sizetype,
  4464.                                 endlink))));
  4465.  
  4466.   void_ftype_ptr_int_int
  4467.     = build_function_type (void_type_node,
  4468.                tree_cons (NULL_TREE, ptr_type_node,
  4469.                       tree_cons (NULL_TREE, integer_type_node,
  4470.                          int_endlink)));
  4471.  
  4472.   string_ftype_ptr_ptr        /* strcpy prototype */
  4473.     = build_function_type (string_type_node,
  4474.                tree_cons (NULL_TREE, string_type_node,
  4475.                       tree_cons (NULL_TREE,
  4476.                          const_string_type_node,
  4477.                          endlink)));
  4478.  
  4479. #if 0
  4480.   /* Not yet.  */
  4481.   strncpy_ftype            /* strncpy prototype */
  4482.     = build_function_type (string_type_node,
  4483.                tree_cons (NULL_TREE, string_type_node,
  4484.                       tree_cons (NULL_TREE, const_string_type_node,
  4485.                          tree_cons (NULL_TREE,
  4486.                                 sizetype,
  4487.                                 endlink))));
  4488. #endif
  4489.  
  4490.   int_ftype_string_string    /* strcmp prototype */
  4491.     = build_function_type (integer_type_node,
  4492.                tree_cons (NULL_TREE, const_string_type_node,
  4493.                       tree_cons (NULL_TREE,
  4494.                          const_string_type_node,
  4495.                          endlink)));
  4496.  
  4497.   sizet_ftype_string        /* strlen prototype */
  4498.     = build_function_type (sizetype,
  4499.                tree_cons (NULL_TREE, const_string_type_node,
  4500.                       endlink));
  4501.  
  4502.   traditional_ptr_type_node
  4503.     = (flag_traditional ? string_type_node : ptr_type_node);
  4504.  
  4505.   memcpy_ftype    /* memcpy prototype */
  4506.     = build_function_type (traditional_ptr_type_node,
  4507.                tree_cons (NULL_TREE, ptr_type_node,
  4508.                       tree_cons (NULL_TREE, const_ptr_type_node,
  4509.                          tree_cons (NULL_TREE,
  4510.                                 sizetype,
  4511.                                 endlink))));
  4512.  
  4513.   if (flag_huge_objects)
  4514.     delta_type_node = long_integer_type_node;
  4515.   else
  4516.     delta_type_node = short_integer_type_node;
  4517.  
  4518.   builtin_function ("__builtin_constant_p", int_ftype_int,
  4519.             BUILT_IN_CONSTANT_P, NULL_PTR);
  4520.  
  4521.   builtin_return_address_fndecl =
  4522.   builtin_function ("__builtin_return_address",
  4523.             build_function_type (ptr_type_node, 
  4524.                      tree_cons (NULL_TREE,
  4525.                             unsigned_type_node,
  4526.                             endlink)),
  4527.             BUILT_IN_RETURN_ADDRESS, NULL_PTR);
  4528.  
  4529.   builtin_function ("__builtin_frame_address",
  4530.             build_function_type (ptr_type_node, 
  4531.                      tree_cons (NULL_TREE,
  4532.                             unsigned_type_node,
  4533.                             endlink)),
  4534.             BUILT_IN_FRAME_ADDRESS, NULL_PTR);
  4535.  
  4536.  
  4537.   builtin_function ("__builtin_alloca",
  4538.             build_function_type (ptr_type_node,
  4539.                      tree_cons (NULL_TREE,
  4540.                             sizetype,
  4541.                             endlink)),
  4542.             BUILT_IN_ALLOCA, "alloca");
  4543. #if 0
  4544.   builtin_function ("alloca",
  4545.             build_function_type (ptr_type_node,
  4546.                      tree_cons (NULL_TREE,
  4547.                             sizetype,
  4548.                             endlink)),
  4549.             BUILT_IN_ALLOCA, NULL_PTR);
  4550. #endif
  4551.  
  4552.   builtin_function ("__builtin_abs", int_ftype_int,
  4553.             BUILT_IN_ABS, NULL_PTR);
  4554.   builtin_function ("__builtin_fabs", double_ftype_double,
  4555.             BUILT_IN_FABS, NULL_PTR);
  4556.   builtin_function ("__builtin_labs", long_ftype_long,
  4557.             BUILT_IN_LABS, NULL_PTR);
  4558.   builtin_function ("__builtin_ffs", int_ftype_int,
  4559.             BUILT_IN_FFS, NULL_PTR);
  4560.   builtin_function ("__builtin_fsqrt", double_ftype_double,
  4561.             BUILT_IN_FSQRT, NULL_PTR);
  4562.   builtin_function ("__builtin_sin", double_ftype_double, 
  4563.             BUILT_IN_SIN, "sin");
  4564.   builtin_function ("__builtin_cos", double_ftype_double, 
  4565.             BUILT_IN_COS, "cos");
  4566.   builtin_function ("__builtin_saveregs",
  4567.             build_function_type (ptr_type_node, NULL_TREE),
  4568.             BUILT_IN_SAVEREGS, NULL_PTR);
  4569. /* EXPAND_BUILTIN_VARARGS is obsolete.  */
  4570. #if 0
  4571.   builtin_function ("__builtin_varargs",
  4572.             build_function_type (ptr_type_node,
  4573.                      tree_cons (NULL_TREE,
  4574.                             integer_type_node,
  4575.                             endlink)),
  4576.             BUILT_IN_VARARGS, NULL_PTR);
  4577. #endif
  4578.   builtin_function ("__builtin_classify_type", default_function_type,
  4579.             BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
  4580.   builtin_function ("__builtin_next_arg",
  4581.             build_function_type (ptr_type_node, NULL_TREE),
  4582.             BUILT_IN_NEXT_ARG, NULL_PTR);
  4583.   builtin_function ("__builtin_args_info",
  4584.             build_function_type (integer_type_node,
  4585.                      tree_cons (NULL_TREE,
  4586.                             integer_type_node,
  4587.                             endlink)),
  4588.             BUILT_IN_ARGS_INFO, NULL_PTR);
  4589.  
  4590.   /* Untyped call and return.  */
  4591.   builtin_function ("__builtin_apply_args",
  4592.             build_function_type (ptr_type_node, NULL_TREE),
  4593.             BUILT_IN_APPLY_ARGS, NULL_PTR);
  4594.  
  4595.   temp = tree_cons (NULL_TREE,
  4596.             build_pointer_type (build_function_type (void_type_node,
  4597.                                  NULL_TREE)),
  4598.             tree_cons (NULL_TREE,
  4599.                    ptr_type_node,
  4600.                    tree_cons (NULL_TREE,
  4601.                       sizetype,
  4602.                       endlink)));
  4603.   builtin_function ("__builtin_apply",
  4604.             build_function_type (ptr_type_node, temp),
  4605.             BUILT_IN_APPLY, NULL_PTR);
  4606.   builtin_function ("__builtin_return",
  4607.             build_function_type (void_type_node,
  4608.                      tree_cons (NULL_TREE,
  4609.                             ptr_type_node,
  4610.                             endlink)),
  4611.             BUILT_IN_RETURN, NULL_PTR);
  4612.  
  4613.   /* Currently under experimentation.  */
  4614.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  4615.             BUILT_IN_MEMCPY, "memcpy");
  4616.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  4617.             BUILT_IN_MEMCMP, "memcmp");
  4618.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  4619.             BUILT_IN_STRCMP, "strcmp");
  4620.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  4621.             BUILT_IN_STRCPY, "strcpy");
  4622. #if 0
  4623.   /* Not yet.  */
  4624.   builtin_function ("__builtin_strncpy", strncpy_ftype,
  4625.             BUILT_IN_STRNCPY, "strncpy");
  4626. #endif
  4627.   builtin_function ("__builtin_strlen", sizet_ftype_string,
  4628.             BUILT_IN_STRLEN, "strlen");
  4629.  
  4630.   if (!flag_no_builtin)
  4631.     {
  4632. #if 0 /* These do not work well with libg++.  */
  4633.       builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
  4634.       builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
  4635.       builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
  4636. #endif
  4637.       builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
  4638.       builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
  4639.             NULL_PTR);
  4640.       builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
  4641.       builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
  4642.             NULL_PTR);
  4643. #if 0
  4644.       /* Not yet.  */
  4645.       builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
  4646. #endif
  4647.       builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
  4648.       builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
  4649.       builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
  4650.     }
  4651.  
  4652. #if 0
  4653.   /* Support for these has not been written in either expand_builtin
  4654.      or build_function_call.  */
  4655.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
  4656.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
  4657.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
  4658.             0);
  4659.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
  4660.   builtin_function ("__builtin_fmod", double_ftype_double_double,
  4661.             BUILT_IN_FMOD, 0);
  4662.   builtin_function ("__builtin_frem", double_ftype_double_double,
  4663.             BUILT_IN_FREM, 0);
  4664.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
  4665.             0);
  4666.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
  4667.             0);
  4668.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
  4669.             0);
  4670. #endif
  4671.  
  4672.   /* C++ extensions */
  4673.  
  4674.   unknown_type_node = make_node (UNKNOWN_TYPE);
  4675. #if 0 /* not yet, should get fixed properly later */
  4676.   pushdecl (make_type_decl (get_identifier ("unknown type"),
  4677.                unknown_type_node));
  4678. #else
  4679.   decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
  4680.             unknown_type_node));
  4681.   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
  4682.   DECL_IGNORED_P (decl) = 1;
  4683.   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
  4684. #endif
  4685.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  4686.   TYPE_ALIGN (unknown_type_node) = 1;
  4687.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  4688.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  4689.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  4690.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
  4691.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  4692.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  4693.  
  4694.   /* This is for handling opaque types in signatures.  */
  4695.   opaque_type_node = copy_node (ptr_type_node);
  4696.   TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
  4697.   record_builtin_type (RID_MAX, 0, opaque_type_node);
  4698.  
  4699.   /* This is special for C++ so functions can be overloaded. */
  4700.   wchar_type_node
  4701.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
  4702.   wchar_type_size = TYPE_PRECISION (wchar_type_node);
  4703.   signed_wchar_type_node = make_signed_type (wchar_type_size);
  4704.   unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
  4705.   wchar_type_node
  4706.     = TREE_UNSIGNED (wchar_type_node)
  4707.       ? unsigned_wchar_type_node
  4708.       : signed_wchar_type_node;
  4709.   record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
  4710.  
  4711.   /* This is for wide string constants.  */
  4712.   wchar_array_type_node
  4713.     = build_array_type (wchar_type_node, array_domain_type);
  4714.  
  4715.   /* This is a hack that should go away when we deliver the
  4716.      real gc code.  */
  4717.   if (flag_gc)
  4718.     {
  4719.       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
  4720.       pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
  4721.     }
  4722.  
  4723.   if (flag_vtable_thunks)
  4724.     {
  4725.       /* Make sure we get a unique function type, so we can give
  4726.      its pointer type a name.  (This wins for gdb.) */
  4727.       tree vfunc_type = make_node (FUNCTION_TYPE);
  4728.       TREE_TYPE (vfunc_type) = integer_type_node;
  4729.       TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
  4730.       layout_type (vfunc_type);
  4731.  
  4732.       vtable_entry_type = build_pointer_type (vfunc_type);
  4733.     }
  4734.   else
  4735.     {
  4736.       vtable_entry_type = make_lang_type (RECORD_TYPE);
  4737.       fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  4738.                      delta_type_node);
  4739.       fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  4740.                      delta_type_node);
  4741.       fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
  4742.                      ptr_type_node);
  4743.       finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
  4744.                double_type_node);
  4745.  
  4746.       /* Make this part of an invisible union.  */
  4747.       fields[3] = copy_node (fields[2]);
  4748.       TREE_TYPE (fields[3]) = delta_type_node;
  4749.       DECL_NAME (fields[3]) = delta2_identifier;
  4750.       DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
  4751.       DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
  4752.       TREE_UNSIGNED (fields[3]) = 0;
  4753.       TREE_CHAIN (fields[2]) = fields[3];
  4754.       vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  4755.     }
  4756.   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
  4757.  
  4758.   vtbl_type_node
  4759.     = build_array_type (vtable_entry_type, NULL_TREE);
  4760.   layout_type (vtbl_type_node);
  4761.   vtbl_type_node = c_build_type_variant (vtbl_type_node, 1, 0);
  4762.   record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
  4763.  
  4764.   /* Simplify life by making a "sigtable_entry_type".  Give its
  4765.      fields names so that the debugger can use them.  */
  4766.  
  4767.   if (flag_handle_signatures)
  4768.     {
  4769.       sigtable_entry_type = make_lang_type (RECORD_TYPE);
  4770.       fields[0] = build_lang_field_decl (FIELD_DECL,
  4771.                      get_identifier (SIGTABLE_CODE_NAME),
  4772.                      short_integer_type_node);
  4773.       fields[1] = build_lang_field_decl (FIELD_DECL,
  4774.                      get_identifier (SIGTABLE_OFFSET_NAME),
  4775.                      short_integer_type_node);
  4776.       fields[2] = build_lang_field_decl (FIELD_DECL,
  4777.                      get_identifier (SIGTABLE_PFN_NAME),
  4778.                      ptr_type_node);
  4779.       finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
  4780.                double_type_node);
  4781.       sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
  4782.       record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
  4783.     }
  4784.  
  4785.   if (flag_dossier)
  4786.     {
  4787.       /* Must build __t_desc type.  Currently, type descriptors look like this:
  4788.  
  4789.      struct __t_desc
  4790.      {
  4791.            const char *name;
  4792.        int size;
  4793.        int bits;
  4794.        struct __t_desc *points_to;
  4795.        int ivars_count, meths_count;
  4796.        struct __i_desc *ivars[];
  4797.        struct __m_desc *meths[];
  4798.        struct __t_desc *parents[];
  4799.        struct __t_desc *vbases[];
  4800.        int offsets[];
  4801.      };
  4802.  
  4803.      ...as per Linton's paper.  */
  4804.  
  4805.       __t_desc_type_node = make_lang_type (RECORD_TYPE);
  4806.       __i_desc_type_node = make_lang_type (RECORD_TYPE);
  4807.       __m_desc_type_node = make_lang_type (RECORD_TYPE);
  4808.       __t_desc_array_type =
  4809.     build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
  4810.       __i_desc_array_type =
  4811.     build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
  4812.       __m_desc_array_type =
  4813.     build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
  4814.  
  4815.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4816.                      string_type_node);
  4817.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
  4818.                      unsigned_type_node);
  4819.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
  4820.                      unsigned_type_node);
  4821.       fields[3] = build_lang_field_decl (FIELD_DECL,
  4822.                      get_identifier ("points_to"),
  4823.                      TYPE_POINTER_TO (__t_desc_type_node));
  4824.       fields[4] = build_lang_field_decl (FIELD_DECL,
  4825.                      get_identifier ("ivars_count"),
  4826.                      integer_type_node);
  4827.       fields[5] = build_lang_field_decl (FIELD_DECL,
  4828.                      get_identifier ("meths_count"),
  4829.                      integer_type_node);
  4830.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
  4831.                      build_pointer_type (__i_desc_array_type));
  4832.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
  4833.                      build_pointer_type (__m_desc_array_type));
  4834.       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
  4835.                      build_pointer_type (__t_desc_array_type));
  4836.       fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
  4837.                      build_pointer_type (__t_desc_array_type));
  4838.       fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
  4839.                      build_pointer_type (integer_type_node));
  4840.       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
  4841.  
  4842.       /* ivar descriptors look like this:
  4843.  
  4844.      struct __i_desc
  4845.      {
  4846.        const char *name;
  4847.        int offset;
  4848.        struct __t_desc *type;
  4849.      };
  4850.       */
  4851.  
  4852.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4853.                      string_type_node);
  4854.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
  4855.                      integer_type_node);
  4856.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
  4857.                      TYPE_POINTER_TO (__t_desc_type_node));
  4858.       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
  4859.                integer_type_node);
  4860.  
  4861.       /* method descriptors look like this:
  4862.  
  4863.      struct __m_desc
  4864.      {
  4865.        const char *name;
  4866.        int vindex;
  4867.        struct __t_desc *vcontext;
  4868.        struct __t_desc *return_type;
  4869.        void (*address)();
  4870.        short parm_count;
  4871.        short required_parms;
  4872.        struct __t_desc *parm_types[];
  4873.      };
  4874.       */
  4875.  
  4876.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4877.                      string_type_node);
  4878.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
  4879.                      integer_type_node);
  4880.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
  4881.                      TYPE_POINTER_TO (__t_desc_type_node));
  4882.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
  4883.                      TYPE_POINTER_TO (__t_desc_type_node));
  4884.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
  4885.                      build_pointer_type (default_function_type));
  4886.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
  4887.                      short_integer_type_node);
  4888.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
  4889.                      short_integer_type_node);
  4890.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
  4891.                      build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
  4892.       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
  4893.                integer_type_node);
  4894.     }
  4895.  
  4896.   /* Now, C++.  */
  4897.   current_lang_name = lang_name_cplusplus;
  4898.   if (flag_dossier)
  4899.     {
  4900.       int i = builtin_type_tdescs_len;
  4901.       while (i > 0)
  4902.     {
  4903.       tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
  4904.       TREE_ASM_WRITTEN (tdesc) = 1;
  4905.       TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
  4906.     }
  4907.     }
  4908.  
  4909.   auto_function (ansi_opname[(int) NEW_EXPR],
  4910.          build_function_type (ptr_type_node,
  4911.                       tree_cons (NULL_TREE, sizetype,
  4912.                          void_list_node)),
  4913.          NOT_BUILT_IN);
  4914.   auto_function (ansi_opname[(int) VEC_NEW_EXPR],
  4915.          build_function_type (ptr_type_node,
  4916.                       tree_cons (NULL_TREE, sizetype,
  4917.                          void_list_node)),
  4918.          NOT_BUILT_IN);
  4919.   auto_function (ansi_opname[(int) DELETE_EXPR],
  4920.          build_function_type (void_type_node,
  4921.                       tree_cons (NULL_TREE, ptr_type_node,
  4922.                          void_list_node)),
  4923.          NOT_BUILT_IN);
  4924.   auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
  4925.          build_function_type (void_type_node,
  4926.                       tree_cons (NULL_TREE, ptr_type_node,
  4927.                          void_list_node)),
  4928.          NOT_BUILT_IN);
  4929.  
  4930.   abort_fndecl
  4931.     = define_function ("abort",
  4932.                build_function_type (void_type_node, void_list_node),
  4933.                NOT_BUILT_IN, 0, 0);
  4934.  
  4935.   /* Perform other language dependent initializations.  */
  4936.   init_class_processing ();
  4937.   init_init_processing ();
  4938.   init_search_processing ();
  4939.  
  4940.   if (flag_handle_exceptions)
  4941.     init_exception_processing ();
  4942.   if (flag_gc)
  4943.     init_gc_processing ();
  4944.   if (flag_no_inline)
  4945.     {
  4946.       flag_inline_functions = 0;
  4947. #if 0
  4948.       /* This causes uneccessary emission of inline functions.  */
  4949.       flag_default_inline = 0;
  4950. #endif
  4951.     }
  4952.   if (flag_cadillac)
  4953.     init_cadillac ();
  4954.  
  4955.   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
  4956.   declare_function_name ();
  4957.  
  4958.   /* Prepare to check format strings against argument lists.  */
  4959.   init_function_format_info ();
  4960. }
  4961.  
  4962. /* Make a definition for a builtin function named NAME and whose data type
  4963.    is TYPE.  TYPE should be a function type with argument types.
  4964.    FUNCTION_CODE tells later passes how to compile calls to this function.
  4965.    See tree.h for its possible values.
  4966.  
  4967.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  4968.    the name to be called if we can't opencode the function.  */
  4969.  
  4970. tree
  4971. define_function (name, type, function_code, pfn, library_name)
  4972.      char *name;
  4973.      tree type;
  4974.      enum built_in_function function_code;
  4975.      void (*pfn)();
  4976.      char *library_name;
  4977. {
  4978.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  4979.   DECL_EXTERNAL (decl) = 1;
  4980.   TREE_PUBLIC (decl) = 1;
  4981.  
  4982.   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
  4983.      we cannot change DECL_ASSEMBLER_NAME until we have installed this
  4984.      function in the namespace.  */
  4985.   if (pfn) (*pfn) (decl);
  4986.   if (library_name)
  4987.     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
  4988.   make_function_rtl (decl);
  4989.   if (function_code != NOT_BUILT_IN)
  4990.     {
  4991.       DECL_BUILT_IN (decl) = 1;
  4992.       DECL_FUNCTION_CODE (decl) = function_code;
  4993.     }
  4994.   return decl;
  4995. }
  4996.  
  4997. /* Called when a declaration is seen that contains no names to declare.
  4998.    If its type is a reference to a structure, union or enum inherited
  4999.    from a containing scope, shadow that tag name for the current scope
  5000.    with a forward reference.
  5001.    If its type defines a new named structure or union
  5002.    or defines an enum, it is valid but we need not do anything here.
  5003.    Otherwise, it is an error.
  5004.  
  5005.    C++: may have to grok the declspecs to learn about static,
  5006.    complain for anonymous unions.  */
  5007.  
  5008. void
  5009. shadow_tag (declspecs)
  5010.      tree declspecs;
  5011. {
  5012.   int found_tag = 0;
  5013.   int warned = 0;
  5014.   tree ob_modifier = NULL_TREE;
  5015.   register tree link;
  5016.   register enum tree_code code, ok_code = ERROR_MARK;
  5017.   register tree t = NULL_TREE;
  5018.  
  5019.   for (link = declspecs; link; link = TREE_CHAIN (link))
  5020.     {
  5021.       register tree value = TREE_VALUE (link);
  5022.  
  5023.       code = TREE_CODE (value);
  5024.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  5025.     {
  5026.       register tree name = TYPE_NAME (value);
  5027.  
  5028.       if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
  5029.         cp_error ("forward declaration of `%#T'", value);
  5030.  
  5031.       if (name == NULL_TREE)
  5032.         name = lookup_tag_reverse (value, NULL_TREE);
  5033.  
  5034.       if (name && TREE_CODE (name) == TYPE_DECL)
  5035.         name = DECL_NAME (name);
  5036.  
  5037.       t = lookup_tag (code, name, inner_binding_level, 1);
  5038.  
  5039.       if (t == NULL_TREE)
  5040.         {
  5041.           push_obstacks (&permanent_obstack, &permanent_obstack);
  5042.           if (IS_AGGR_TYPE_CODE (code))
  5043.         t = make_lang_type (code);
  5044.           else
  5045.         t = make_node (code);
  5046.           pushtag (name, t, 0);
  5047.           pop_obstacks ();
  5048.           ok_code = code;
  5049.         }
  5050.       else if (name != NULL_TREE || code == ENUMERAL_TYPE)
  5051.         ok_code = code;
  5052.  
  5053.       if (ok_code != ERROR_MARK)
  5054.         found_tag++;
  5055.       else
  5056.         {
  5057.           if (!warned)
  5058.         pedwarn ("useless keyword or type name in declaration");
  5059.           warned = 1;
  5060.         }
  5061.     }
  5062.       else if (value == ridpointers[(int) RID_STATIC]
  5063.            || value == ridpointers[(int) RID_EXTERN]
  5064.            || value == ridpointers[(int) RID_AUTO]
  5065.            || value == ridpointers[(int) RID_REGISTER])
  5066.     ob_modifier = value;
  5067.     }
  5068.  
  5069.   /* This is where the variables in an anonymous union are
  5070.      declared.  An anonymous union declaration looks like:
  5071.      union { ... } ;
  5072.      because there is no declarator after the union, the parser
  5073.      sends that declaration here.  */
  5074.   if (ok_code == UNION_TYPE
  5075.       && t != NULL_TREE
  5076.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  5077.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  5078.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  5079.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
  5080.     {
  5081.       /* ANSI C++ June 5 1992 WP 9.5.3.  Anonymous unions may not have
  5082.      function members.  */
  5083.       if (TYPE_FIELDS (t))
  5084.     {
  5085.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
  5086.                       NULL_TREE);
  5087.       finish_anon_union (decl);
  5088.     }
  5089.       else
  5090.     error ("anonymous union cannot have a function member");
  5091.     }
  5092.   else
  5093.     {
  5094.       /* Anonymous unions are objects, that's why we only check for
  5095.      inappropriate specifiers in this branch.  */
  5096.       if (ob_modifier)
  5097.     cp_error ("`%D' can only be specified for objects and functions",
  5098.           ob_modifier);
  5099.  
  5100.       if (ok_code == RECORD_TYPE
  5101.       && found_tag == 1
  5102.       && TYPE_LANG_SPECIFIC (t)
  5103.       && CLASSTYPE_DECLARED_EXCEPTION (t))
  5104.     {
  5105.       if (TYPE_SIZE (t))
  5106.         cp_error ("redeclaration of exception `%T'", t);
  5107.       else
  5108.         {
  5109.           tree ename, decl;
  5110.  
  5111.           push_obstacks (&permanent_obstack, &permanent_obstack);
  5112.  
  5113.           pushclass (t, 0);
  5114.  
  5115.           ename = TYPE_NAME (t);
  5116.           if (TREE_CODE (ename) == TYPE_DECL)
  5117.         ename = DECL_NAME (ename);
  5118.           decl = build_lang_field_decl (VAR_DECL, ename, t);
  5119.  
  5120.           pop_obstacks ();
  5121.         }
  5122.     }
  5123.       else if (found_tag == 0)
  5124.     pedwarn ("abstract declarator used as declaration");
  5125.       else if (!warned && found_tag > 1)
  5126.     pedwarn ("multiple types in one declaration");
  5127.     }
  5128. }
  5129.  
  5130. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  5131.  
  5132. tree
  5133. groktypename (typename)
  5134.      tree typename;
  5135. {
  5136.   if (TREE_CODE (typename) != TREE_LIST)
  5137.     return typename;
  5138.   return grokdeclarator (TREE_VALUE (typename),
  5139.              TREE_PURPOSE (typename),
  5140.              TYPENAME, 0, NULL_TREE);
  5141. }
  5142.  
  5143. /* Decode a declarator in an ordinary declaration or data definition.
  5144.    This is called as soon as the type information and variable name
  5145.    have been parsed, before parsing the initializer if any.
  5146.    Here we create the ..._DECL node, fill in its type,
  5147.    and put it on the list of decls for the current context.
  5148.    The ..._DECL node is returned as the value.
  5149.  
  5150.    Exception: for arrays where the length is not specified,
  5151.    the type is left null, to be filled in by `finish_decl'.
  5152.  
  5153.    Function definitions do not come here; they go to start_function
  5154.    instead.  However, external and forward declarations of functions
  5155.    do go through here.  Structure field declarations are done by
  5156.    grokfield and not through here.  */
  5157.  
  5158. /* Set this to zero to debug not using the temporary obstack
  5159.    to parse initializers.  */
  5160. int debug_temp_inits = 1;
  5161.  
  5162. tree
  5163. start_decl (declarator, declspecs, initialized, raises)
  5164.      tree declarator, declspecs;
  5165.      int initialized;
  5166.      tree raises;
  5167. {
  5168.   register tree decl;
  5169.   register tree type, tem;
  5170.   tree context;
  5171.   extern int have_extern_spec;
  5172.   extern int used_extern_spec;
  5173.  
  5174.   int init_written = initialized;
  5175.  
  5176.   /* This should only be done once on the top most decl. */
  5177.   if (have_extern_spec && !used_extern_spec)
  5178.     {
  5179.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
  5180.                   declspecs);
  5181.       used_extern_spec = 1;
  5182.     }
  5183.  
  5184.   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
  5185.   if (decl == NULL_TREE || decl == void_type_node)
  5186.     return NULL_TREE;
  5187.  
  5188.   type = TREE_TYPE (decl);
  5189.  
  5190.   /* Don't lose if destructors must be executed at file-level.  */
  5191.   if (TREE_STATIC (decl)
  5192.       && TYPE_NEEDS_DESTRUCTOR (type)
  5193.       && !TREE_PERMANENT (decl))
  5194.     {
  5195.       push_obstacks (&permanent_obstack, &permanent_obstack);
  5196.       decl = copy_node (decl);
  5197.       if (TREE_CODE (type) == ARRAY_TYPE)
  5198.     {
  5199.       tree itype = TYPE_DOMAIN (type);
  5200.       if (itype && ! TREE_PERMANENT (itype))
  5201.         {
  5202.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  5203.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  5204.           TREE_TYPE (decl) = type;
  5205.         }
  5206.     }
  5207.       pop_obstacks ();
  5208.     }
  5209.  
  5210.   /* Interesting work for this is done in `finish_exception_decl'.  */
  5211.   if (TREE_CODE (type) == RECORD_TYPE
  5212.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  5213.     return decl;
  5214.  
  5215.   /* Corresponding pop_obstacks is done in `finish_decl'.  */
  5216.   push_obstacks_nochange ();
  5217.  
  5218.   context
  5219.     = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
  5220.       ? DECL_CLASS_CONTEXT (decl)
  5221.       : DECL_CONTEXT (decl);
  5222.  
  5223.   if (processing_template_decl)
  5224.     {
  5225.       tree d;
  5226.       if (TREE_CODE (decl) == FUNCTION_DECL)
  5227.         {
  5228.           /* Declarator is a call_expr; extract arguments from it, since
  5229.              grokdeclarator didn't do it.  */
  5230.           tree args;
  5231.           args = copy_to_permanent (last_function_parms);
  5232.           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
  5233.             {
  5234.           tree t = TREE_TYPE (decl);
  5235.           
  5236.               t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
  5237.           if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
  5238.         {
  5239.           t = build_pointer_type (t); /* base type of `this' */
  5240. #if 1
  5241.           /* I suspect this is wrong. */
  5242.           t = build_type_variant (t, flag_this_is_variable <= 0,
  5243.                       0); /* type of `this' */
  5244. #else
  5245.           t = build_type_variant (t, 0, 0); /* type of `this' */
  5246. #endif
  5247.           t = build (PARM_DECL, t, this_identifier);
  5248.           TREE_CHAIN (t) = args;
  5249.           args = t;
  5250.         }
  5251.         }
  5252.           DECL_ARGUMENTS (decl) = args;
  5253.         }
  5254.       d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
  5255.       if (interface_unknown && flag_external_templates
  5256.       && ! DECL_IN_SYSTEM_HEADER (decl))
  5257.     warn_if_unknown_interface ();
  5258.       TREE_PUBLIC (d) = TREE_PUBLIC (decl) =
  5259.     flag_external_templates && !interface_unknown;
  5260.       TREE_STATIC (d) = TREE_STATIC (decl);
  5261.       DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
  5262.                && !(context && !DECL_THIS_EXTERN (decl)));
  5263.       DECL_TEMPLATE_RESULT (d) = decl;
  5264.       decl = d;
  5265.     }
  5266.  
  5267.   /* If this type of object needs a cleanup, and control may
  5268.      jump past it, make a new binding level so that it is cleaned
  5269.      up only when it is initialized first.  */
  5270.   if (TYPE_NEEDS_DESTRUCTOR (type)
  5271.       && current_binding_level->more_cleanups_ok == 0)
  5272.     pushlevel_temporary (1);
  5273.  
  5274.   if (initialized)
  5275.     /* Is it valid for this decl to have an initializer at all?
  5276.        If not, set INITIALIZED to zero, which will indirectly
  5277.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  5278.     switch (TREE_CODE (decl))
  5279.       {
  5280.       case TYPE_DECL:
  5281.     /* typedef foo = bar  means give foo the same type as bar.
  5282.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  5283.        Any other case of an initialization in a TYPE_DECL is an error.  */
  5284.     if (pedantic || list_length (declspecs) > 1)
  5285.       {
  5286.         cp_error ("typedef `%D' is initialized", decl);
  5287.         initialized = 0;
  5288.       }
  5289.     break;
  5290.  
  5291.       case FUNCTION_DECL:
  5292.     cp_error ("function `%#D' is initialized like a variable", decl);
  5293.     initialized = 0;
  5294.     break;
  5295.  
  5296.       default:
  5297.     /* Don't allow initializations for incomplete types except for
  5298.        arrays which might be completed by the initialization.  */
  5299.     if (type == error_mark_node)
  5300.       ;            /* Don't complain again.  */
  5301.     else if (TYPE_SIZE (type) != NULL_TREE)
  5302.       ;                     /* A complete type is ok.  */
  5303.     else if (TREE_CODE (type) != ARRAY_TYPE)
  5304.       {
  5305.         cp_error ("variable `%#D' has initializer but incomplete type",
  5306.               decl);
  5307.         initialized = 0;
  5308.       }
  5309.     else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
  5310.       {
  5311.         cp_error ("elements of array `%#D' have incomplete type", decl);
  5312.         initialized = 0;
  5313.       }
  5314.       }
  5315.  
  5316.   if (!initialized
  5317.       && TREE_CODE (decl) != TYPE_DECL
  5318.       && TREE_CODE (decl) != TEMPLATE_DECL
  5319.       && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
  5320.     {
  5321.       if (TYPE_SIZE (type) == NULL_TREE)
  5322.     {
  5323.       cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
  5324.          decl);
  5325.       /* Change the type so that assemble_variable will give
  5326.          DECL an rtl we can live with: (mem (const_int 0)).  */
  5327.       TREE_TYPE (decl) = error_mark_node;
  5328.       type = error_mark_node;
  5329.     }
  5330.       else
  5331.     {
  5332.       /* If any base type in the hierarchy of TYPE needs a constructor,
  5333.          then we set initialized to 1.  This way any nodes which are
  5334.          created for the purposes of initializing this aggregate
  5335.          will live as long as it does.  This is necessary for global
  5336.          aggregates which do not have their initializers processed until
  5337.          the end of the file.  */
  5338.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  5339.     }
  5340.     }
  5341.  
  5342.   if (initialized)
  5343.     {
  5344.       if (current_binding_level != global_binding_level
  5345.       && DECL_EXTERNAL (decl))
  5346.     cp_warning ("declaration of `%#D' has `extern' and is initialized",
  5347.             decl);
  5348.       DECL_EXTERNAL (decl) = 0;
  5349.       if (current_binding_level == global_binding_level)
  5350.     TREE_STATIC (decl) = 1;
  5351.  
  5352.       /* Tell `pushdecl' this is an initialized decl
  5353.      even though we don't yet have the initializer expression.
  5354.      Also tell `finish_decl' it may store the real initializer.  */
  5355.       DECL_INITIAL (decl) = error_mark_node;
  5356.     }
  5357.  
  5358.   if (context && TYPE_SIZE (context) != NULL_TREE)
  5359.     {
  5360.       if (TREE_CODE (decl) == VAR_DECL)
  5361.     {
  5362.       tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
  5363.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  5364.         cp_error ("`%#D' is not a static member of `%#T'", decl, context);
  5365.       else if (duplicate_decls (decl, field))
  5366.         decl = field;
  5367.     }
  5368.       
  5369.       /* If it was not explicitly declared `extern',
  5370.      revoke any previous claims of DECL_EXTERNAL.  */
  5371.       if (DECL_THIS_EXTERN (decl) == 0)
  5372.     DECL_EXTERNAL (decl) = 0;
  5373.       if (DECL_LANG_SPECIFIC (decl))
  5374.     DECL_IN_AGGR_P (decl) = 0;
  5375.       pushclass (context, 2);
  5376.     }
  5377.  
  5378.   /* Add this decl to the current binding level, but not if it
  5379.      comes from another scope, e.g. a static member variable.
  5380.      TEM may equal DECL or it may be a previous decl of the same name.  */
  5381.   
  5382.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  5383.       || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
  5384.       || TREE_CODE (type) == LANG_TYPE)
  5385.     tem = decl;
  5386.   else
  5387.     tem = pushdecl (decl);
  5388.          
  5389.   /* Tell the back-end to use or not use .common as appropriate.  If we say
  5390.      -fconserve-space, we want this to save space, at the expense of wrong
  5391.      semantics.  If we say -fno-conserve-space, we want this to produce
  5392.      errors about redefs; to do this we force variables into the data
  5393.      segment.  Common storage is okay for non-public uninitialized data;
  5394.      the linker can't match it with storage from other files, and we may
  5395.      save some disk space.  */
  5396.   DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
  5397.  
  5398. #if 0
  5399.   /* We don't do this yet for GNU C++.  */
  5400.   /* For a local variable, define the RTL now.  */
  5401.   if (current_binding_level != global_binding_level
  5402.       /* But not if this is a duplicate decl
  5403.      and we preserved the rtl from the previous one
  5404.      (which may or may not happen).  */
  5405.       && DECL_RTL (tem) == NULL_RTX)
  5406.     {
  5407.       if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
  5408.     expand_decl (tem);
  5409.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  5410.            && DECL_INITIAL (tem) != NULL_TREE)
  5411.     expand_decl (tem);
  5412.     }
  5413. #endif
  5414.  
  5415.   if (TREE_CODE (decl) == TEMPLATE_DECL)
  5416.     {
  5417.       tree result = DECL_TEMPLATE_RESULT (decl);
  5418.       if (DECL_CONTEXT (result) != NULL_TREE)
  5419.     {
  5420.           tree type;
  5421.           type = DECL_CONTEXT (result);
  5422.  
  5423.       if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
  5424.         {
  5425.           cp_error ("declaration of `%D' in non-template type `%T'",
  5426.             decl, type);
  5427.           return NULL_TREE;
  5428.         }
  5429.  
  5430.       if (TREE_CODE (result) == FUNCTION_DECL)
  5431.         return tem;
  5432.       else if (TREE_CODE (result) == VAR_DECL)
  5433.         {
  5434. #if 0
  5435.               tree tmpl = UPT_TEMPLATE (type);
  5436.           
  5437.           fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
  5438.           print_node_brief (stderr, "", DECL_NAME (tem), 0);
  5439.           fprintf (stderr, " to class %s\n",
  5440.                IDENTIFIER_POINTER (DECL_NAME (tmpl)));
  5441.               DECL_TEMPLATE_MEMBERS (tmpl)
  5442.                 = perm_tree_cons (DECL_NAME (tem), tem,
  5443.                   DECL_TEMPLATE_MEMBERS (tmpl));
  5444.           return tem;
  5445. #else
  5446.           sorry ("static data member templates");
  5447.           return NULL_TREE;
  5448. #endif
  5449.         }
  5450.       else
  5451.         my_friendly_abort (13);
  5452.         }
  5453.       else if (TREE_CODE (result) == FUNCTION_DECL)
  5454.         /*tem = push_overloaded_decl (tem, 0)*/;
  5455.       else if (TREE_CODE (result) == VAR_DECL)
  5456.     {
  5457.       cp_error ("data template `%#D' must be member of a class template",
  5458.             result);
  5459.       return NULL_TREE;
  5460.     }
  5461.       else if (TREE_CODE (result) == TYPE_DECL)
  5462.     {
  5463.       cp_error ("invalid template `%#D'", result);
  5464.       return NULL_TREE;
  5465.     }
  5466.       else
  5467.     my_friendly_abort (14);
  5468.     }
  5469.  
  5470.   if (init_written
  5471.       && ! (TREE_CODE (tem) == PARM_DECL
  5472.         || (TREE_READONLY (tem)
  5473.         && (TREE_CODE (tem) == VAR_DECL
  5474.             || TREE_CODE (tem) == FIELD_DECL))))
  5475.     {
  5476.       /* When parsing and digesting the initializer,
  5477.      use temporary storage.  Do this even if we will ignore the value.  */
  5478.       if (current_binding_level == global_binding_level && debug_temp_inits)
  5479.     {
  5480.       if (TYPE_NEEDS_CONSTRUCTING (type)
  5481.           || TREE_CODE (type) == REFERENCE_TYPE)
  5482.         /* In this case, the initializer must lay down in permanent
  5483.            storage, since it will be saved until `finish_file' is run.   */
  5484.         ;
  5485.       else
  5486.         temporary_allocation ();
  5487.     }
  5488.     }
  5489.  
  5490.   if (flag_cadillac)
  5491.     cadillac_start_decl (tem);
  5492.  
  5493.   return tem;
  5494. }
  5495.  
  5496. #if 0                /* unused */
  5497. static void
  5498. make_temporary_for_reference (decl, ctor_call, init, cleanupp)
  5499.      tree decl, ctor_call, init;
  5500.      tree *cleanupp;
  5501. {
  5502.   tree type = TREE_TYPE (decl);
  5503.   tree target_type = TREE_TYPE (type);
  5504.   tree tmp, tmp_addr;
  5505.  
  5506.   if (ctor_call)
  5507.     {
  5508.       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
  5509.       if (TREE_CODE (tmp_addr) == NOP_EXPR)
  5510.     tmp_addr = TREE_OPERAND (tmp_addr, 0);
  5511.       my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
  5512.       tmp = TREE_OPERAND (tmp_addr, 0);
  5513.     }
  5514.   else
  5515.     {
  5516.       tmp = get_temp_name (target_type,
  5517.                current_binding_level == global_binding_level);
  5518.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  5519.     }
  5520.  
  5521.   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  5522.   DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
  5523.   TREE_TYPE (DECL_INITIAL (decl)) = type;
  5524.   if (TYPE_NEEDS_CONSTRUCTING (target_type))
  5525.     {
  5526.       if (current_binding_level == global_binding_level)
  5527.     {
  5528.       /* lay this variable out now.  Otherwise `output_addressed_constants'
  5529.          gets confused by its initializer.  */
  5530.       make_decl_rtl (tmp, NULL_PTR, 1);
  5531.       static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  5532.     }
  5533.       else
  5534.     {
  5535.       if (ctor_call != NULL_TREE)
  5536.         init = ctor_call;
  5537.       else
  5538.         init = build_method_call (tmp, constructor_name_full (target_type),
  5539.                       build_tree_list (NULL_TREE, init),
  5540.                       NULL_TREE, LOOKUP_NORMAL);
  5541.       DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
  5542.                        DECL_INITIAL (decl));
  5543.       *cleanupp = maybe_build_cleanup (tmp);
  5544.     }
  5545.     }
  5546.   else
  5547.     {
  5548.       DECL_INITIAL (tmp) = init;
  5549.       TREE_STATIC (tmp) = current_binding_level == global_binding_level;
  5550.       finish_decl (tmp, init, 0, 0);
  5551.     }
  5552.   if (TREE_STATIC (tmp))
  5553.     preserve_initializer ();
  5554. }
  5555. #endif
  5556.  
  5557. /* Handle initialization of references.
  5558.    These three arguments from from `finish_decl', and have the
  5559.    same meaning here that they do there.  */
  5560. /* quotes on semantics can be found in ARM 8.4.3. */
  5561. static void
  5562. grok_reference_init (decl, type, init, cleanupp)
  5563.      tree decl, type, init;
  5564.      tree *cleanupp;
  5565. {
  5566.   tree tmp;
  5567.  
  5568.   if (init == NULL_TREE)
  5569.     {
  5570.       if (DECL_LANG_SPECIFIC (decl) == 0
  5571.       || DECL_IN_AGGR_P (decl) == 0)
  5572.     {
  5573.       cp_error ("`%D' declared as reference but not initialized", decl);
  5574.       if (TREE_CODE (decl) == VAR_DECL)
  5575.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  5576.     }
  5577.       return;
  5578.     }
  5579.  
  5580.   if (init == error_mark_node)
  5581.     return;
  5582.  
  5583.   if (TREE_CODE (type) == REFERENCE_TYPE
  5584.       && TREE_CODE (init) == CONSTRUCTOR)
  5585.     {
  5586.       cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
  5587.       return;
  5588.     }
  5589.  
  5590.   if (TREE_CODE (init) == TREE_LIST)
  5591.     init = build_compound_expr (init);
  5592.  
  5593.   if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  5594.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  5595.     {
  5596.       /* Note: default conversion is only called in very special cases.  */
  5597.       init = default_conversion (init);
  5598.     }
  5599.  
  5600.   tmp = convert_to_reference
  5601.     (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
  5602.  
  5603.   if (tmp == error_mark_node)
  5604.     goto fail;
  5605.   else if (tmp != NULL_TREE)
  5606.     {
  5607.       tree subtype = TREE_TYPE (type);
  5608.       init = tmp;
  5609.  
  5610.       /* Associate the cleanup with the reference so that we
  5611.      don't get burned by "aggressive" cleanup policy.  */
  5612.       if (TYPE_NEEDS_DESTRUCTOR (subtype))
  5613.     {
  5614.       if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
  5615.         {
  5616.           *cleanupp = TREE_OPERAND (init, 2);
  5617.           TREE_OPERAND (init, 2) = error_mark_node;
  5618.         }
  5619.       else
  5620.         {
  5621.           if (TREE_CODE (tmp) == ADDR_EXPR)
  5622.         tmp = TREE_OPERAND (tmp, 0);
  5623.           if (TREE_CODE (tmp) == TARGET_EXPR)
  5624.         {
  5625.           *cleanupp = build_delete
  5626.             (TYPE_POINTER_TO (subtype),
  5627.              build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
  5628.              integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
  5629.           TREE_OPERAND (tmp, 2) = error_mark_node;
  5630.         }
  5631.         }
  5632.     }
  5633.  
  5634.       DECL_INITIAL (decl) = save_expr (init);
  5635.     }
  5636.   else
  5637.     {
  5638.       cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
  5639.       goto fail;
  5640.     }
  5641.  
  5642.   /* ?? Can this be optimized in some cases to
  5643.      hand back the DECL_INITIAL slot??  */
  5644.   if (TYPE_SIZE (TREE_TYPE (type)))
  5645.     {
  5646.       init = convert_from_reference (decl);
  5647.       if (TREE_PERMANENT (decl))
  5648.     init = copy_to_permanent (init);
  5649.       SET_DECL_REFERENCE_SLOT (decl, init);
  5650.     }
  5651.  
  5652.   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
  5653.     {
  5654.       expand_static_init (decl, DECL_INITIAL (decl));
  5655.       DECL_INITIAL (decl) = NULL_TREE;
  5656.     }
  5657.   return;
  5658.  
  5659.  fail:
  5660.   if (TREE_CODE (decl) == VAR_DECL)
  5661.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  5662.   return;
  5663. }
  5664.  
  5665. /* Finish processing of a declaration;
  5666.    install its line number and initial value.
  5667.    If the length of an array type is not known before,
  5668.    it must be determined now, from the initial value, or it is an error.
  5669.  
  5670.    Call `pop_obstacks' iff NEED_POP is nonzero.
  5671.  
  5672.    For C++, `finish_decl' must be fairly evasive:  it must keep initializers
  5673.    for aggregates that have constructors alive on the permanent obstack,
  5674.    so that the global initializing functions can be written at the end.
  5675.  
  5676.    INIT0 holds the value of an initializer that should be allowed to escape
  5677.    the normal rules.
  5678.  
  5679.    For functions that take default parameters, DECL points to its
  5680.    "maximal" instantiation.  `finish_decl' must then also declared its
  5681.    subsequently lower and lower forms of instantiation, checking for
  5682.    ambiguity as it goes.  This can be sped up later.  */
  5683.  
  5684. void
  5685. finish_decl (decl, init, asmspec_tree, need_pop)
  5686.      tree decl, init;
  5687.      tree asmspec_tree;
  5688.      int need_pop;
  5689. {
  5690.   register tree type;
  5691.   tree cleanup = NULL_TREE, ttype;
  5692.   int was_incomplete;
  5693.   int temporary = allocation_temporary_p ();
  5694.   char *asmspec = NULL;
  5695.   int was_readonly = 0;
  5696.  
  5697.   /* If this is 0, then we did not change obstacks.  */
  5698.   if (! decl)
  5699.     {
  5700.       if (init)
  5701.     error ("assignment (not initialization) in declaration");
  5702.       return;
  5703.     }
  5704.  
  5705.   /* If a name was specified, get the string.  */
  5706.   if (asmspec_tree)
  5707.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  5708.  
  5709.   /* If the type of the thing we are declaring either has
  5710.      a constructor, or has a virtual function table pointer,
  5711.      AND its initialization was accepted by `start_decl',
  5712.      then we stayed on the permanent obstack through the
  5713.      declaration, otherwise, changed obstacks as GCC would.  */
  5714.  
  5715.   type = TREE_TYPE (decl);
  5716.  
  5717.   was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
  5718.  
  5719.   /* Take care of TYPE_DECLs up front.  */
  5720.   if (TREE_CODE (decl) == TYPE_DECL)
  5721.     {
  5722.       if (init && DECL_INITIAL (decl))
  5723.     {
  5724.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  5725.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  5726.       DECL_INITIAL (decl) = init = NULL_TREE;
  5727.     }
  5728.       if (type != error_mark_node
  5729.       && IS_AGGR_TYPE (type) && DECL_NAME (decl))
  5730.     {
  5731.       if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  5732.         cp_warning ("shadowing previous type declaration of `%#D'", decl);
  5733.       set_identifier_type_value (DECL_NAME (decl), type);
  5734.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  5735.     }
  5736.       GNU_xref_decl (current_function_decl, decl);
  5737.       rest_of_decl_compilation (decl, NULL_PTR,
  5738.                 DECL_CONTEXT (decl) == NULL_TREE, 0);
  5739.       goto finish_end;
  5740.     }
  5741.   if (type != error_mark_node && IS_AGGR_TYPE (type)
  5742.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  5743.     {
  5744.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  5745.       goto finish_end;
  5746.     }
  5747.   if (TREE_CODE (decl) != FUNCTION_DECL)
  5748.     {
  5749.       ttype = target_type (type);
  5750. #if 0 /* WTF?  -KR
  5751.      Leave this out until we can figure out why it was
  5752.      needed/desirable in the first place.  Then put a comment
  5753.      here explaining why.  Or just delete the code if no ill
  5754.      effects arise.  */
  5755.       if (TYPE_NAME (ttype)
  5756.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  5757.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
  5758.     {
  5759.       tree old_id = TYPE_IDENTIFIER (ttype);
  5760.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  5761.       /* Need to preserve template data for UPT nodes.  */
  5762.       tree old_template = IDENTIFIER_TEMPLATE (old_id);
  5763.       newname[0] = '_';
  5764.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  5765.          IDENTIFIER_LENGTH (old_id) + 1);
  5766.       old_id = get_identifier (newname);
  5767.       lookup_tag_reverse (ttype, old_id);
  5768.       TYPE_IDENTIFIER (ttype) = old_id;
  5769.       IDENTIFIER_TEMPLATE (old_id) = old_template;
  5770.     }
  5771. #endif
  5772.     }
  5773.  
  5774.   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
  5775.       && TYPE_NEEDS_CONSTRUCTING (type))
  5776.     {
  5777.  
  5778.       /* Currently, GNU C++ puts constants in text space, making them
  5779.      impossible to initialize.  In the future, one would hope for
  5780.      an operating system which understood the difference between
  5781.      initialization and the running of a program.  */
  5782.       was_readonly = 1;
  5783.       TREE_READONLY (decl) = 0;
  5784.     }
  5785.  
  5786.   if (TREE_CODE (decl) == FIELD_DECL)
  5787.     {
  5788.       if (init && init != error_mark_node)
  5789.     my_friendly_assert (TREE_PERMANENT (init), 147);
  5790.  
  5791.       if (asmspec)
  5792.     {
  5793.       /* This must override the asm specifier which was placed
  5794.          by grokclassfn.  Lay this out fresh.
  5795.          
  5796.          @@ Should emit an error if this redefines an asm-specified
  5797.          @@ name, or if we have already used the function's name.  */
  5798.       DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
  5799.       DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  5800.       make_decl_rtl (decl, asmspec, 0);
  5801.     }
  5802.     }
  5803.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  5804.   else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
  5805.     init = NULL_TREE;
  5806.   else if (DECL_EXTERNAL (decl))
  5807.     ;
  5808.   else if (TREE_CODE (type) == REFERENCE_TYPE
  5809.        || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
  5810.     {
  5811.       grok_reference_init (decl, type, init, &cleanup);
  5812.       init = NULL_TREE;
  5813.     }
  5814.  
  5815.   GNU_xref_decl (current_function_decl, decl);
  5816.  
  5817.   if (TREE_CODE (decl) == FIELD_DECL)
  5818.     ;
  5819.   else if (TREE_CODE (decl) == CONST_DECL)
  5820.     {
  5821.       my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
  5822.  
  5823.       DECL_INITIAL (decl) = init;
  5824.  
  5825.       /* This will keep us from needing to worry about our obstacks.  */
  5826.       my_friendly_assert (init != NULL_TREE, 149);
  5827.       init = NULL_TREE;
  5828.     }
  5829.   else if (init)
  5830.     {
  5831.       if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
  5832.     {
  5833.       if (TREE_CODE (type) == ARRAY_TYPE)
  5834.         init = digest_init (type, init, (tree *) 0);
  5835.       else if (TREE_CODE (init) == CONSTRUCTOR)
  5836.         {
  5837.           if (TYPE_NEEDS_CONSTRUCTING (type))
  5838.         {
  5839.           cp_error ("`%D' must be initialized by constructor, not by `{...}'",
  5840.                 decl);
  5841.           init = error_mark_node;
  5842.         }
  5843.           else
  5844.         goto dont_use_constructor;
  5845.         }
  5846. #if 0
  5847.       /* fix this in `build_functional_cast' instead.
  5848.          Here's the trigger code:
  5849.  
  5850.         struct ostream
  5851.         {
  5852.           ostream ();
  5853.           ostream (int, char *);
  5854.           ostream (char *);
  5855.           operator char *();
  5856.           ostream (void *);
  5857.           operator void *();
  5858.           operator << (int);
  5859.         };
  5860.         int buf_size = 1024;
  5861.         static char buf[buf_size];
  5862.         const char *debug(int i) {
  5863.           char *b = &buf[0];
  5864.           ostream o = ostream(buf_size, b);
  5865.           o << i;
  5866.           return buf;
  5867.         }
  5868.         */
  5869.  
  5870.       else if (TREE_CODE (init) == TARGET_EXPR
  5871.            && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
  5872.         {
  5873.           /* User wrote something like `foo x = foo (args)'  */
  5874.           my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
  5875.           my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
  5876.  
  5877.           /* User wrote exactly `foo x = foo (args)'  */
  5878.           if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
  5879.         {
  5880.           init = build (CALL_EXPR, TREE_TYPE (init),
  5881.                 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
  5882.                 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
  5883.           TREE_SIDE_EFFECTS (init) = 1;
  5884.         }
  5885.         }
  5886. #endif
  5887.  
  5888.       /* We must hide the initializer so that expand_decl
  5889.          won't try to do something it does not understand.  */
  5890.       if (current_binding_level == global_binding_level)
  5891.         {
  5892.           tree value;
  5893.           if (DECL_COMMON (decl))
  5894.         /* Should this be a NULL_TREE? */
  5895.         value = error_mark_node;
  5896.           else
  5897.         value = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
  5898.           DECL_INITIAL (decl) = value;
  5899.         }
  5900.       else
  5901.         DECL_INITIAL (decl) = error_mark_node;
  5902.     }
  5903.       else
  5904.     {
  5905.     dont_use_constructor:
  5906.       if (TREE_CODE (init) != TREE_VEC)
  5907.         init = store_init_value (decl, init);
  5908.  
  5909.       /* Don't let anyone try to initialize this variable
  5910.          until we are ready to do so.  */
  5911.       if (init)
  5912.         {
  5913.           tree value;
  5914.           if (DECL_COMMON (decl))
  5915.         value = error_mark_node;
  5916.           else
  5917.         value = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
  5918.           DECL_INITIAL (decl) = value;
  5919.         }
  5920.     }
  5921.     }
  5922.   else if (DECL_EXTERNAL (decl))
  5923.     ;
  5924.   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  5925.        && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
  5926.     {
  5927.       tree ctype = type;
  5928.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  5929.     ctype = TREE_TYPE (ctype);
  5930.       if (! TYPE_NEEDS_CONSTRUCTING (ctype))
  5931.     {
  5932.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  5933.         cp_error ("structure `%D' with uninitialized const members", decl);
  5934.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  5935.         cp_error ("structure `%D' with uninitialized reference members",
  5936.               decl);
  5937.     }
  5938.  
  5939.       if (TREE_CODE (decl) == VAR_DECL
  5940.       && !DECL_INITIAL (decl)
  5941.       && !TYPE_NEEDS_CONSTRUCTING (type)
  5942.       && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  5943.     cp_error ("uninitialized const `%D'", decl);
  5944.  
  5945.       /* Initialize variables in need of static initialization with
  5946.      an empty CONSTRUCTOR to keep assemble_variable from putting them in
  5947.      the wrong program space.  */
  5948.       if (flag_pic == 0
  5949.       && TREE_STATIC (decl)
  5950.       && TREE_PUBLIC (decl)
  5951.       && ! DECL_EXTERNAL (decl)
  5952.       && TREE_CODE (decl) == VAR_DECL
  5953.       && TYPE_NEEDS_CONSTRUCTING (type)
  5954.       && (DECL_INITIAL (decl) == NULL_TREE
  5955.           || DECL_INITIAL (decl) == error_mark_node)
  5956.       && ! DECL_COMMON (decl))
  5957.     DECL_INITIAL (decl) = build (CONSTRUCTOR, type, NULL_TREE,
  5958.                      NULL_TREE);
  5959.     }
  5960.   else if (TREE_CODE (decl) == VAR_DECL
  5961.        && TREE_CODE (type) != REFERENCE_TYPE
  5962.        && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  5963.     {
  5964.       /* ``Unless explicitly declared extern, a const object does not have
  5965.      external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
  5966.      However, if it's `const int foo = 1; const int foo;', don't complain
  5967.      about the second decl, since it does have an initializer before.
  5968.      We deliberately don't complain about arrays, because they're
  5969.      supposed to be initialized by a constructor.  */
  5970.       if (! DECL_INITIAL (decl)
  5971.       && TREE_CODE (type) != ARRAY_TYPE
  5972.       && (!pedantic || !current_class_type))
  5973.     cp_error ("uninitialized const `%#D'", decl);
  5974.     }
  5975.  
  5976.   /* For top-level declaration, the initial value was read in
  5977.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  5978.      must go in the permanent obstack; but don't discard the
  5979.      temporary data yet.  */
  5980.  
  5981.   if (current_binding_level == global_binding_level && temporary)
  5982.     end_temporary_allocation ();
  5983.  
  5984.   /* Deduce size of array from initialization, if not already known.  */
  5985.  
  5986.   if (TREE_CODE (type) == ARRAY_TYPE
  5987.       && TYPE_DOMAIN (type) == NULL_TREE
  5988.       && TREE_CODE (decl) != TYPE_DECL)
  5989.     {
  5990.       int do_default
  5991.     = (TREE_STATIC (decl)
  5992.        /* Even if pedantic, an external linkage array
  5993.           may have incomplete type at first.  */
  5994.        ? pedantic && ! DECL_EXTERNAL (decl)
  5995.        : !DECL_EXTERNAL (decl));
  5996.       tree initializer = init ? init : DECL_INITIAL (decl);
  5997.       int failure = complete_array_type (type, initializer, do_default);
  5998.  
  5999.       if (failure == 1)
  6000.     cp_error ("initializer fails to determine size of `%D'", decl);
  6001.  
  6002.       if (failure == 2)
  6003.     {
  6004.       if (do_default)
  6005.         cp_error ("array size missing in `%D'", decl);
  6006.       /* If a `static' var's size isn't known, make it extern as
  6007.          well as static, so it does not get allocated.  If it's not
  6008.          `static', then don't mark it extern; finish_incomplete_decl
  6009.          will give it a default size and it will get allocated.  */
  6010.       else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
  6011.         DECL_EXTERNAL (decl) = 1;
  6012.     }
  6013.  
  6014.       if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
  6015.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  6016.                   integer_zero_node))
  6017.     cp_error ("zero-size array `%D'", decl);
  6018.  
  6019.       layout_decl (decl, 0);
  6020.     }
  6021.  
  6022.   if (TREE_CODE (decl) == VAR_DECL)
  6023.     {
  6024.       if (DECL_SIZE (decl) == NULL_TREE
  6025.       && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
  6026.     layout_decl (decl, 0);
  6027.  
  6028.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
  6029.     {
  6030.       /* A static variable with an incomplete type:
  6031.          that is an error if it is initialized.
  6032.          Otherwise, let it through, but if it is not `extern'
  6033.          then it may cause an error message later.  */
  6034.       if (DECL_INITIAL (decl) != NULL_TREE)
  6035.         cp_error ("storage size of `%D' isn't known", decl);
  6036.       init = NULL_TREE;
  6037.     }
  6038.       else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
  6039.     {
  6040.       /* An automatic variable with an incomplete type: that is an error.
  6041.          Don't talk about array types here, since we took care of that
  6042.          message in grokdeclarator.  */
  6043.       cp_error ("storage size of `%D' isn't known", decl);
  6044.       TREE_TYPE (decl) = error_mark_node;
  6045.     }
  6046.       else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  6047.     /* Let debugger know it should output info for this type.  */
  6048.     note_debug_info_needed (ttype);
  6049.  
  6050.       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
  6051.       && DECL_SIZE (decl) != NULL_TREE
  6052.       && ! TREE_CONSTANT (DECL_SIZE (decl)))
  6053.     {
  6054.       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
  6055.         constant_expression_warning (DECL_SIZE (decl));
  6056.       else
  6057.         cp_error ("storage size of `%D' isn't constant", decl);
  6058.     }
  6059.  
  6060.       if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
  6061.     {
  6062.       int yes = suspend_momentary ();
  6063.  
  6064.       /* If INIT comes from a functional cast, use the cleanup
  6065.          we built for that.  Otherwise, make our own cleanup.  */
  6066.       if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
  6067.           && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
  6068.         {
  6069.           cleanup = TREE_OPERAND (init, 2);
  6070.           init = TREE_OPERAND (init, 0);
  6071.           current_binding_level->have_cleanups = 1;
  6072.         }
  6073.       else
  6074.         cleanup = maybe_build_cleanup (decl);
  6075.       resume_momentary (yes);
  6076.     }
  6077.     }
  6078.   /* PARM_DECLs get cleanups, too.  */
  6079.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  6080.     {
  6081.       if (temporary)
  6082.     end_temporary_allocation ();
  6083.       cleanup = maybe_build_cleanup (decl);
  6084.       if (temporary)
  6085.     resume_temporary_allocation ();
  6086.     }
  6087.  
  6088.   /* Output the assembler code and/or RTL code for variables and functions,
  6089.      unless the type is an undefined structure or union.
  6090.      If not, it will get done when the type is completed.  */
  6091.  
  6092.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  6093.       || TREE_CODE (decl) == RESULT_DECL)
  6094.     {
  6095.       /* ??? FIXME: What about nested classes?  */
  6096.       int toplev = (current_binding_level == global_binding_level
  6097.             || pseudo_global_level_p ());
  6098.       int was_temp
  6099.     = ((flag_traditional
  6100.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  6101.        && allocation_temporary_p ());
  6102.  
  6103.       if (was_temp)
  6104.     end_temporary_allocation ();
  6105.  
  6106.       if (TREE_CODE (decl) == VAR_DECL
  6107.       && current_binding_level != global_binding_level
  6108.       && ! TREE_STATIC (decl)
  6109.       && type_needs_gc_entry (type))
  6110.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  6111.  
  6112.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  6113.     make_decl_rtl (decl, NULL_PTR, toplev);
  6114.       else if (TREE_CODE (decl) == VAR_DECL
  6115.            && TREE_READONLY (decl)
  6116.            && DECL_INITIAL (decl) != NULL_TREE
  6117.            && DECL_INITIAL (decl) != error_mark_node
  6118.            && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
  6119.     {
  6120.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  6121.  
  6122.       if (asmspec)
  6123.         DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  6124.  
  6125.       if (! toplev
  6126.           && TREE_STATIC (decl)
  6127.           && ! TREE_SIDE_EFFECTS (decl)
  6128.           && ! TREE_PUBLIC (decl)
  6129.           && ! DECL_EXTERNAL (decl)
  6130.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  6131.           && DECL_MODE (decl) != BLKmode)
  6132.         {
  6133.           /* If this variable is really a constant, then fill its DECL_RTL
  6134.          slot with something which won't take up storage.
  6135.          If something later should take its address, we can always give
  6136.          it legitimate RTL at that time.  */
  6137.           DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  6138.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  6139.           TREE_ASM_WRITTEN (decl) = 1;
  6140.         }
  6141.       else if (toplev && ! TREE_PUBLIC (decl))
  6142.         {
  6143.           /* If this is a static const, change its apparent linkage
  6144.          if it belongs to a #pragma interface.  */
  6145.           if (!interface_unknown)
  6146.         {
  6147.           TREE_PUBLIC (decl) = 1;
  6148.           DECL_EXTERNAL (decl) = interface_only;
  6149.         }
  6150.           make_decl_rtl (decl, asmspec, toplev);
  6151.         }
  6152.       else
  6153.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6154.     }
  6155.       else if (TREE_CODE (decl) == VAR_DECL
  6156.            && DECL_LANG_SPECIFIC (decl)
  6157.            && DECL_IN_AGGR_P (decl))
  6158.     {
  6159.       if (TREE_STATIC (decl))
  6160.         {
  6161.           if (init == NULL_TREE
  6162. #ifdef DEFAULT_STATIC_DEFS
  6163.           /* If this code is dead, then users must
  6164.              explicitly declare static member variables
  6165.              outside the class def'n as well.  */
  6166.           && TYPE_NEEDS_CONSTRUCTING (type)
  6167. #endif
  6168.           )
  6169.         {
  6170.           DECL_EXTERNAL (decl) = 1;
  6171.           make_decl_rtl (decl, asmspec, 1);
  6172.         }
  6173.           else
  6174.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6175.         }
  6176.       else
  6177.         /* Just a constant field.  Should not need any rtl.  */
  6178.         goto finish_end0;
  6179.     }
  6180.       else
  6181.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6182.  
  6183.       if (was_temp)
  6184.     resume_temporary_allocation ();
  6185.  
  6186.       if (type != error_mark_node
  6187.       && TYPE_LANG_SPECIFIC (type)
  6188.       && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  6189.     abstract_virtuals_error (decl, type);
  6190.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6191.         || TREE_CODE (type) == METHOD_TYPE)
  6192.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6193.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  6194.     abstract_virtuals_error (decl, TREE_TYPE (type));
  6195.  
  6196.       if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
  6197.     signature_error (decl, type);
  6198.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6199.         || TREE_CODE (type) == METHOD_TYPE)
  6200.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6201.            && IS_SIGNATURE (TREE_TYPE (type)))
  6202.     signature_error (decl, TREE_TYPE (type));
  6203.  
  6204.       if (TREE_CODE (decl) == FUNCTION_DECL)
  6205.     {
  6206. #if 0
  6207.       /* C++: Handle overloaded functions with default parameters.  */
  6208.       if (DECL_OVERLOADED (decl))
  6209.         {
  6210.           tree parmtypes = TYPE_ARG_TYPES (type);
  6211.           tree prev = NULL_TREE;
  6212.           tree original_name = DECL_NAME (decl);
  6213.           struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
  6214.           /* All variants will share an uncollectible lang_decl.  */
  6215.           copy_decl_lang_specific (decl);
  6216.  
  6217.           while (parmtypes && parmtypes != void_list_node)
  6218.         {
  6219.           /* The default value for the parameter in parmtypes is
  6220.              stored in the TREE_PURPOSE of the TREE_LIST.  */ 
  6221.           if (TREE_PURPOSE (parmtypes))
  6222.             {
  6223.               tree fnname, fndecl;
  6224.               tree *argp;
  6225.  
  6226.               argp = prev ? & TREE_CHAIN (prev)
  6227.             : & TYPE_ARG_TYPES (type);
  6228.  
  6229.               *argp = NULL_TREE;
  6230.               fnname = build_decl_overload (original_name,
  6231.                             TYPE_ARG_TYPES (type), 0);
  6232.               *argp = parmtypes;
  6233.               fndecl = build_decl (FUNCTION_DECL, fnname, type);
  6234.               DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
  6235.               TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
  6236.               DECL_INLINE (fndecl) = DECL_INLINE (decl);
  6237.               /* Keep G++ from thinking this function is unused.
  6238.              It is only used to speed up search in name space.  */
  6239.               TREE_USED (fndecl) = 1;
  6240.               TREE_ASM_WRITTEN (fndecl) = 1;
  6241.               DECL_INITIAL (fndecl) = NULL_TREE;
  6242.               DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
  6243.               fndecl = pushdecl (fndecl);
  6244.               DECL_INITIAL (fndecl) = error_mark_node;
  6245.               DECL_RTL (fndecl) = DECL_RTL (decl);
  6246.             }
  6247.           prev = parmtypes;
  6248.           parmtypes = TREE_CHAIN (parmtypes);
  6249.         }
  6250.           DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
  6251.         }
  6252. #endif
  6253.     }
  6254.       else if (DECL_EXTERNAL (decl))
  6255.     ;
  6256.       else if (TREE_STATIC (decl) && type != error_mark_node)
  6257.     {
  6258.       /* Cleanups for static variables are handled by `finish_file'.  */
  6259.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
  6260.         expand_static_init (decl, init);
  6261.       else if (TYPE_NEEDS_DESTRUCTOR (type))
  6262.         static_aggregates = perm_tree_cons (NULL_TREE, decl,
  6263.                         static_aggregates);
  6264.  
  6265.       /* Make entry in appropriate vector.  */
  6266.       if (flag_gc && type_needs_gc_entry (type))
  6267.         build_static_gc_entry (decl, type);
  6268.     }
  6269.       else if (! toplev)
  6270.     {
  6271.       tree old_cleanups = cleanups_this_call;
  6272.       /* This is a declared decl which must live until the
  6273.          end of the binding contour.  It may need a cleanup.  */
  6274.  
  6275.       /* Recompute the RTL of a local array now
  6276.          if it used to be an incomplete type.  */
  6277.       if (was_incomplete && ! TREE_STATIC (decl))
  6278.         {
  6279.           /* If we used it already as memory, it must stay in memory.  */
  6280.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  6281.           /* If it's still incomplete now, no init will save it.  */
  6282.           if (DECL_SIZE (decl) == NULL_TREE)
  6283.         DECL_INITIAL (decl) = NULL_TREE;
  6284.           expand_decl (decl);
  6285.         }
  6286.       else if (! TREE_ASM_WRITTEN (decl)
  6287.            && (TYPE_SIZE (type) != NULL_TREE
  6288.                || TREE_CODE (type) == ARRAY_TYPE))
  6289.         {
  6290.           /* Do this here, because we did not expand this decl's
  6291.          rtl in start_decl.  */
  6292.           if (DECL_RTL (decl) == NULL_RTX)
  6293.         expand_decl (decl);
  6294.           else if (cleanup)
  6295.         {
  6296.           /* XXX: Why don't we use decl here?  */
  6297.           /* Ans: Because it was already expanded? */
  6298.           if (! expand_decl_cleanup (NULL_TREE, cleanup))
  6299.             cp_error ("parser lost in parsing declaration of `%D'",
  6300.                   decl);
  6301.           /* Cleanup used up here.  */
  6302.           cleanup = NULL_TREE;
  6303.         }
  6304.         }
  6305.  
  6306.       if (DECL_SIZE (decl) && type != error_mark_node)
  6307.         {
  6308.           /* Compute and store the initial value.  */
  6309.           expand_decl_init (decl);
  6310.  
  6311.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  6312.         {
  6313.           emit_line_note (DECL_SOURCE_FILE (decl),
  6314.                   DECL_SOURCE_LINE (decl));
  6315.           expand_aggr_init (decl, init, 0);
  6316.         }
  6317.  
  6318.           /* Set this to 0 so we can tell whether an aggregate
  6319.          which was initialized was ever used.  */
  6320.           if (TYPE_NEEDS_CONSTRUCTING (type))
  6321.         TREE_USED (decl) = 0;
  6322.  
  6323.           /* Store the cleanup, if there was one.  */
  6324.           if (cleanup)
  6325.         {
  6326.           if (! expand_decl_cleanup (decl, cleanup))
  6327.             cp_error ("parser lost in parsing declaration of `%D'",
  6328.                   decl);
  6329.         }
  6330.         }
  6331.       /* Cleanup any temporaries needed for the initial value.  */
  6332.       expand_cleanups_to (old_cleanups);
  6333.     }
  6334.     finish_end0:
  6335.  
  6336.       /* Undo call to `pushclass' that was done in `start_decl'
  6337.      due to initialization of qualified member variable.
  6338.      I.e., Foo::x = 10;  */
  6339.       {
  6340.     tree context = DECL_CONTEXT (decl);
  6341.     if (context
  6342.         && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
  6343.         && (TREE_CODE (decl) == VAR_DECL
  6344.         /* We also have a pushclass done that we need to undo here
  6345.            if we're at top level and declare a method.  */
  6346.         || (TREE_CODE (decl) == FUNCTION_DECL
  6347.             /* If size hasn't been set, we're still defining it,
  6348.                and therefore inside the class body; don't pop
  6349.                the binding level..  */
  6350.             && TYPE_SIZE (context) != NULL_TREE
  6351.             /* The binding level gets popped elsewhere for a
  6352.                friend declaration inside another class.  */
  6353.             /*
  6354.             && TYPE_IDENTIFIER (context) == current_class_name
  6355.             */
  6356.             && context == current_class_type
  6357.             )))
  6358.       popclass (1);
  6359.       }
  6360.     }
  6361.  
  6362.  finish_end:
  6363.  
  6364.   /* If requested, warn about definitions of large data objects.  */
  6365.  
  6366.   if (warn_larger_than
  6367.       && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
  6368.       && !DECL_EXTERNAL (decl))
  6369.     {
  6370.       register tree decl_size = DECL_SIZE (decl);
  6371.  
  6372.       if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
  6373.     {
  6374.       unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
  6375.  
  6376.       if (units > larger_than_size)
  6377.         warning_with_decl (decl, "size of `%s' is %u bytes", units);
  6378.     }
  6379.     }
  6380.  
  6381.   if (need_pop)
  6382.     {
  6383.       /* Resume permanent allocation, if not within a function.  */
  6384.       /* The corresponding push_obstacks_nochange is in start_decl,
  6385.      start_method, groktypename, and in grokfield.  */
  6386.       pop_obstacks ();
  6387.     }
  6388.  
  6389.   if (was_readonly)
  6390.     TREE_READONLY (decl) = 1;
  6391.  
  6392.   if (flag_cadillac)
  6393.     cadillac_finish_decl (decl);
  6394. }
  6395.  
  6396. void
  6397. expand_static_init (decl, init)
  6398.      tree decl;
  6399.      tree init;
  6400. {
  6401.   tree oldstatic = value_member (decl, static_aggregates);
  6402.   tree old_cleanups;
  6403.  
  6404.   if (oldstatic)
  6405.     {
  6406.       if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
  6407.     cp_error ("multiple initializations given for `%D'", decl);
  6408.     }
  6409.   else if (current_binding_level != global_binding_level
  6410.        && current_binding_level->pseudo_global == 0)
  6411.     {
  6412.       /* Emit code to perform this initialization but once.  */
  6413.       tree temp;
  6414.  
  6415.       /* Remember this information until end of file. */
  6416.       push_obstacks (&permanent_obstack, &permanent_obstack);
  6417.  
  6418.       /* Emit code to perform this initialization but once.  */
  6419.       temp = get_temp_name (integer_type_node, 1);
  6420.       rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
  6421.       expand_start_cond (build_binary_op (EQ_EXPR, temp,
  6422.                       integer_zero_node, 1), 0);
  6423.       old_cleanups = cleanups_this_call;
  6424.       expand_assignment (temp, integer_one_node, 0, 0);
  6425.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  6426.     {
  6427.       expand_aggr_init (decl, init, 0);
  6428.       do_pending_stack_adjust ();
  6429.     }
  6430.       else
  6431.     expand_assignment (decl, init, 0, 0);
  6432.       /* Cleanup any temporaries needed for the initial value.  */
  6433.       expand_cleanups_to (old_cleanups);
  6434.       expand_end_cond ();
  6435.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  6436.     {
  6437.       static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
  6438.       TREE_STATIC (static_aggregates) = 1;
  6439.     }
  6440.  
  6441.       /* Resume old (possibly temporary) allocation. */
  6442.       pop_obstacks ();
  6443.     }
  6444.   else
  6445.     {
  6446.       /* This code takes into account memory allocation
  6447.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  6448.      does not hold for this object, then we must make permanent
  6449.      the storage currently in the temporary obstack.  */
  6450.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  6451.     preserve_initializer ();
  6452.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  6453.     }
  6454. }
  6455.  
  6456. /* Make TYPE a complete type based on INITIAL_VALUE.
  6457.    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
  6458.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  6459.  
  6460. int
  6461. complete_array_type (type, initial_value, do_default)
  6462.      tree type, initial_value;
  6463.      int do_default;
  6464. {
  6465.   register tree maxindex = NULL_TREE;
  6466.   int value = 0;
  6467.  
  6468.   if (initial_value)
  6469.     {
  6470.       /* Note MAXINDEX  is really the maximum index,
  6471.      one less than the size.  */
  6472.       if (TREE_CODE (initial_value) == STRING_CST)
  6473.     maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
  6474.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  6475.     {
  6476.       register int nelts
  6477.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  6478.       maxindex = build_int_2 (nelts - 1, - (nelts == 0));
  6479.     }
  6480.       else
  6481.     {
  6482.       /* Make an error message unless that happened already.  */
  6483.       if (initial_value != error_mark_node)
  6484.         value = 1;
  6485.  
  6486.       /* Prevent further error messages.  */
  6487.       maxindex = build_int_2 (0, 0);
  6488.     }
  6489.     }
  6490.  
  6491.   if (!maxindex)
  6492.     {
  6493.       if (do_default)
  6494.     maxindex = build_int_2 (0, 0);
  6495.       value = 2;
  6496.     }
  6497.  
  6498.   if (maxindex)
  6499.     {
  6500.       tree itype;
  6501.  
  6502.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  6503.       if (!TREE_TYPE (maxindex))
  6504.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  6505.       if (initial_value)
  6506.         itype = TREE_TYPE (initial_value);
  6507.       else
  6508.     itype = NULL;
  6509.       if (itype && !TYPE_DOMAIN (itype))
  6510.     TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
  6511.     }
  6512.  
  6513.   /* Lay out the type now that we can get the real answer.  */
  6514.  
  6515.   layout_type (type);
  6516.  
  6517.   return value;
  6518. }
  6519.  
  6520. /* Return zero if something is declared to be a member of type
  6521.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  6522.    message to print in that case.  Otherwise, quietly return 1.  */
  6523. static int
  6524. member_function_or_else (ctype, cur_type, string)
  6525.      tree ctype, cur_type;
  6526.      char *string;
  6527. {
  6528.   if (ctype && ctype != cur_type)
  6529.     {
  6530.       error (string, TYPE_NAME_STRING (ctype));
  6531.       return 0;
  6532.     }
  6533.   return 1;
  6534. }
  6535.  
  6536. /* Subroutine of `grokdeclarator'.  */
  6537.  
  6538. /* Generate errors possibly applicable for a given set of specifiers.
  6539.    This is for ARM $7.1.2.  */
  6540. static void
  6541. bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
  6542.      tree object;
  6543.      char *type;
  6544.      int virtualp, quals, friendp, raises, inlinep;
  6545. {
  6546.   if (virtualp)
  6547.     cp_error ("`%D' declared as a `virtual' %s", object, type);
  6548.   if (inlinep)
  6549.     cp_error ("`%D' declared as an `inline' %s", object, type);
  6550.   if (quals)
  6551.     cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
  6552.           object, type);
  6553.   if (friendp)
  6554.     cp_error_at ("invalid friend declaration", object);
  6555.   if (raises)
  6556.     cp_error_at ("invalid raises declaration", object);
  6557. }
  6558.  
  6559. /* CTYPE is class type, or null if non-class.
  6560.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  6561.    or METHOD_TYPE.
  6562.    DECLARATOR is the function's name.
  6563.    VIRTUALP is truthvalue of whether the function is virtual or not.
  6564.    FLAGS are to be passed through to `grokclassfn'.
  6565.    QUALS are qualifiers indicating whether the function is `const'
  6566.    or `volatile'.
  6567.    RAISES is a list of exceptions that this function can raise.
  6568.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  6569.    not look, and -1 if we should not call `grokclassfn' at all.  */
  6570. static tree
  6571. grokfndecl (ctype, type, declarator, virtualp, flags, quals,
  6572.         raises, check, publicp)
  6573.      tree ctype, type;
  6574.      tree declarator;
  6575.      int virtualp;
  6576.      enum overload_flags flags;
  6577.      tree quals, raises;
  6578.      int check, publicp;
  6579. {
  6580.   tree cname, decl;
  6581.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  6582.  
  6583.   if (ctype)
  6584.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  6585.       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
  6586.   else
  6587.     cname = NULL_TREE;
  6588.  
  6589.   if (raises)
  6590.     {
  6591.       type = build_exception_variant (ctype, type, raises);
  6592.       raises = TYPE_RAISES_EXCEPTIONS (type);
  6593.     }
  6594.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  6595.   /* propagate volatile out from type to decl */
  6596.   if (TYPE_VOLATILE (type))
  6597.       TREE_THIS_VOLATILE (decl) = 1;
  6598.  
  6599.   /* Should probably propagate const out from type to decl I bet (mrs).  */
  6600.   if (staticp)
  6601.     {
  6602.       DECL_STATIC_FUNCTION_P (decl) = 1;
  6603.       DECL_CONTEXT (decl) = ctype;
  6604.       DECL_CLASS_CONTEXT (decl) = ctype;
  6605.     }
  6606.  
  6607.   if (publicp)
  6608.     TREE_PUBLIC (decl) = 1;
  6609.  
  6610.   DECL_EXTERNAL (decl) = 1;
  6611.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  6612.     {
  6613.       cp_error ("%smember function `%D' cannot have `%T' method qualifier",
  6614.         (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
  6615.       quals = NULL_TREE;
  6616.     }
  6617.  
  6618.   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
  6619.     grok_op_properties (decl, virtualp, check < 0);
  6620.  
  6621.   /* Caller will do the rest of this.  */
  6622.   if (check < 0)
  6623.     return decl;
  6624.  
  6625.   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
  6626.     {
  6627.       tree tmp;
  6628.       /* Just handle constructors here.  We could do this
  6629.      inside the following if stmt, but I think
  6630.      that the code is more legible by breaking this
  6631.      case out.  See comments below for what each of
  6632.      the following calls is supposed to do.  */
  6633.       DECL_CONSTRUCTOR_P (decl) = 1;
  6634.  
  6635.       grokclassfn (ctype, declarator, decl, flags, quals);
  6636.       if (check)
  6637.     check_classfn (ctype, declarator, decl);
  6638.       if (! grok_ctor_properties (ctype, decl))
  6639.     return NULL_TREE;
  6640.  
  6641.       if (check == 0 && ! current_function_decl)
  6642.     {
  6643.       /* FIXME: this should only need to look at
  6644.              IDENTIFIER_GLOBAL_VALUE.  */
  6645.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  6646.       if (tmp == NULL_TREE)
  6647.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  6648.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  6649.         cp_error ("inconsistent declarations for `%D'", decl);
  6650.       else
  6651.         {
  6652.           duplicate_decls (decl, tmp);
  6653.           decl = tmp;
  6654.           /* avoid creating circularities.  */
  6655.           DECL_CHAIN (decl) = NULL_TREE;
  6656.         }
  6657.       make_decl_rtl (decl, NULL_PTR, 1);
  6658.     }
  6659.     }
  6660.   else
  6661.     {
  6662.       tree tmp;
  6663.  
  6664.       /* Function gets the ugly name, field gets the nice one.
  6665.      This call may change the type of the function (because
  6666.      of default parameters)!  */
  6667.       if (ctype != NULL_TREE)
  6668.     grokclassfn (ctype, cname, decl, flags, quals);
  6669.  
  6670.       if (ctype != NULL_TREE && check)
  6671.     check_classfn (ctype, cname, decl);
  6672.  
  6673.       if (ctype == NULL_TREE || check)
  6674.     return decl;
  6675.  
  6676.       /* Now install the declaration of this function so that others may
  6677.      find it (esp. its DECL_FRIENDLIST).  Don't do this for local class
  6678.      methods, though.  */
  6679.       if (! current_function_decl)
  6680.     {
  6681.       /* FIXME: this should only need to look at
  6682.              IDENTIFIER_GLOBAL_VALUE.  */
  6683.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  6684.       if (tmp == NULL_TREE)
  6685.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  6686.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  6687.         cp_error ("inconsistent declarations for `%D'", decl);
  6688.       else
  6689.         {
  6690.           duplicate_decls (decl, tmp);
  6691.           decl = tmp;
  6692.           /* avoid creating circularities.  */
  6693.           DECL_CHAIN (decl) = NULL_TREE;
  6694.         }
  6695.       make_decl_rtl (decl, NULL_PTR, 1);
  6696.     }
  6697.  
  6698.       /* If this declaration supersedes the declaration of
  6699.      a method declared virtual in the base class, then
  6700.      mark this field as being virtual as well.  */
  6701.       {
  6702.     tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
  6703.     int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  6704.  
  6705.     for (i = 0; i < n_baselinks; i++)
  6706.       {
  6707.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  6708.         if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
  6709.         || flag_all_virtual == 1)
  6710.           {
  6711.         tmp = get_matching_virtual (base_binfo, decl,
  6712.                         flags == DTOR_FLAG);
  6713.         if (tmp)
  6714.           {
  6715.             /* If this function overrides some virtual in some base
  6716.                class, then the function itself is also necessarily
  6717.                virtual, even if the user didn't explicitly say so.  */
  6718.             DECL_VIRTUAL_P (decl) = 1;
  6719.  
  6720.             /* The TMP we really want is the one from the deepest
  6721.                baseclass on this path, taking care not to
  6722.                duplicate if we have already found it (via another
  6723.                path to its virtual baseclass.  */
  6724.             if (staticp)
  6725.               {
  6726.             cp_error ("method `%D' may not be declared static",
  6727.                   decl);
  6728.             cp_error_at ("(since `%D' declared virtual in base class.)",
  6729.                      tmp);
  6730.             break;
  6731.               }
  6732.             virtualp = 1;
  6733.  
  6734.             {
  6735.               /* The argument types may have changed... */
  6736.               tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  6737.               tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  6738.  
  6739.               argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  6740.                           TREE_CHAIN (argtypes));
  6741.               /* But the return type has not.  */
  6742.               type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  6743.               if (raises)
  6744.             {
  6745.               type = build_exception_variant (ctype, type, raises);
  6746.               raises = TYPE_RAISES_EXCEPTIONS (type);
  6747.             }
  6748.               TREE_TYPE (decl) = type;
  6749.               DECL_VINDEX (decl)
  6750.             = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
  6751.             }
  6752.             break;
  6753.           }
  6754.           }
  6755.       }
  6756.       }
  6757.       if (virtualp)
  6758.     {
  6759.       if (DECL_VINDEX (decl) == NULL_TREE)
  6760.         DECL_VINDEX (decl) = error_mark_node;
  6761.       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
  6762.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  6763.           /* If this function is derived from a template, don't
  6764.          make it public.  This shouldn't be here, but there's
  6765.          no good way to override the interface pragmas for one
  6766.          function or class only.  Bletch.  */
  6767.           && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
  6768.           && (write_virtuals == 2
  6769.           || (write_virtuals == 3
  6770.               && CLASSTYPE_INTERFACE_KNOWN (ctype))))
  6771.         TREE_PUBLIC (decl) = 1;
  6772.     }
  6773.     }
  6774.   return decl;
  6775. }
  6776.  
  6777. static tree
  6778. grokvardecl (type, declarator, specbits, initialized)
  6779.      tree type;
  6780.      tree declarator;
  6781.      RID_BIT_TYPE specbits;
  6782.      int initialized;
  6783. {
  6784.   tree decl;
  6785.  
  6786.   if (TREE_CODE (type) == OFFSET_TYPE)
  6787.     {
  6788.       /* If you declare a static member so that it
  6789.      can be initialized, the code will reach here.  */
  6790.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  6791.       type = TREE_TYPE (type);
  6792.       decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6793.       DECL_CONTEXT (decl) = basetype;
  6794.       DECL_CLASS_CONTEXT (decl) = basetype;
  6795.     }
  6796.   else
  6797.     decl = build_decl (VAR_DECL, declarator, type);
  6798.  
  6799.   if (RIDBIT_SETP (RID_EXTERN, specbits))
  6800.     {
  6801.       DECL_THIS_EXTERN (decl) = 1;
  6802.       DECL_EXTERNAL (decl) = !initialized;
  6803.     }
  6804.  
  6805.   /* In class context, static means one per class,
  6806.      public access, and static storage.  */
  6807.   if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
  6808.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  6809.     {
  6810.       TREE_PUBLIC (decl) = 1;
  6811.       TREE_STATIC (decl) = 1;
  6812.       DECL_EXTERNAL (decl) = 0;
  6813.     }
  6814.   /* At top level, either `static' or no s.c. makes a definition
  6815.      (perhaps tentative), and absence of `static' makes it public.  */
  6816.   else if (current_binding_level == global_binding_level)
  6817.     {
  6818.       TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
  6819.       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
  6820.     }
  6821.   /* Not at top level, only `static' makes a static definition.  */
  6822.   else
  6823.     {
  6824.       TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
  6825.       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
  6826.     }
  6827.   return decl;
  6828. }
  6829.  
  6830. /* Create a canonical pointer to member function type. */
  6831.  
  6832. tree
  6833. build_ptrmemfunc_type (type)
  6834.      tree type;
  6835. {
  6836.   tree fields[4];
  6837.   tree t;
  6838.   tree u;
  6839.  
  6840.   /* If a canonical type already exists for this type, use it.  We use
  6841.      this method instead of type_hash_canon, because it only does a
  6842.      simple equality check on the list of field members.  */
  6843.  
  6844.   if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
  6845.     return t;
  6846.  
  6847.   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
  6848.  
  6849.   u = make_lang_type (UNION_TYPE);
  6850.   fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
  6851.   fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
  6852.                      delta_type_node);
  6853.   finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
  6854.   TYPE_NAME (u) = NULL_TREE;
  6855.  
  6856.   t = make_lang_type (RECORD_TYPE);
  6857.  
  6858.   /* Let the front-end know this is a pointer to member function. */
  6859.   TYPE_PTRMEMFUNC_FLAG(t) = 1;
  6860.  
  6861.   fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  6862.                      delta_type_node);
  6863.   fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  6864.                      delta_type_node);
  6865.   fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
  6866.   finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
  6867.  
  6868.   pop_obstacks ();
  6869.  
  6870.   /* Zap out the name so that the back-end will give us the debugging
  6871.      information for this anonymous RECORD_TYPE.  */
  6872.   TYPE_NAME (t) = NULL_TREE;
  6873.  
  6874.   TYPE_SET_PTRMEMFUNC_TYPE (type, t);
  6875.  
  6876.   /* Seems to be wanted. */
  6877.   CLASSTYPE_GOT_SEMICOLON (t) = 1;
  6878.   return t;
  6879. }
  6880.  
  6881. /* Given declspecs and a declarator,
  6882.    determine the name and type of the object declared
  6883.    and construct a ..._DECL node for it.
  6884.    (In one case we can return a ..._TYPE node instead.
  6885.     For invalid input we sometimes return 0.)
  6886.  
  6887.    DECLSPECS is a chain of tree_list nodes whose value fields
  6888.     are the storage classes and type specifiers.
  6889.  
  6890.    DECL_CONTEXT says which syntactic context this declaration is in:
  6891.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  6892.      FUNCDEF for a function definition.  Like NORMAL but a few different
  6893.       error messages in each case.  Return value may be zero meaning
  6894.       this definition is too screwy to try to parse.
  6895.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  6896.       handle member functions (which have FIELD context).
  6897.       Return value may be zero meaning this definition is too screwy to
  6898.       try to parse.
  6899.      PARM for a parameter declaration (either within a function prototype
  6900.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  6901.      TYPENAME if for a typename (in a cast or sizeof).
  6902.       Don't make a DECL node; just return the ..._TYPE node.
  6903.      FIELD for a struct or union field; make a FIELD_DECL.
  6904.      BITFIELD for a field with specified width.
  6905.    INITIALIZED is 1 if the decl has an initializer.
  6906.  
  6907.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  6908.    It may also be so in the PARM case, for a prototype where the
  6909.    argument type is specified but not the name.
  6910.  
  6911.    This function is where the complicated C meanings of `static'
  6912.    and `extern' are interpreted.
  6913.  
  6914.    For C++, if there is any monkey business to do, the function which
  6915.    calls this one must do it, i.e., prepending instance variables,
  6916.    renaming overloaded function names, etc.
  6917.  
  6918.    Note that for this C++, it is an error to define a method within a class
  6919.    which does not belong to that class.
  6920.  
  6921.    Except in the case where SCOPE_REFs are implicitly known (such as
  6922.    methods within a class being redundantly qualified),
  6923.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  6924.    (class_name::decl_name).  The caller must also deal with this.
  6925.  
  6926.    If a constructor or destructor is seen, and the context is FIELD,
  6927.    then the type gains the attribute TREE_HAS_x.  If such a declaration
  6928.    is erroneous, NULL_TREE is returned.
  6929.  
  6930.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  6931.    function, these are the qualifiers to give to the `this' pointer.
  6932.  
  6933.    May return void_type_node if the declarator turned out to be a friend.
  6934.    See grokfield for details.  */
  6935.  
  6936. enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
  6937.  
  6938. tree
  6939. grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
  6940.      tree declspecs;
  6941.      tree declarator;
  6942.      enum decl_context decl_context;
  6943.      int initialized;
  6944.      tree raises;
  6945. {
  6946.   RID_BIT_TYPE specbits;
  6947.   int nclasses = 0;
  6948.   tree spec;
  6949.   tree type = NULL_TREE;
  6950.   int longlong = 0;
  6951.   int constp;
  6952.   int volatilep;
  6953.   int virtualp, friendp, inlinep, staticp;
  6954.   int explicit_int = 0;
  6955.   int explicit_char = 0;
  6956.   int opaque_typedef = 0;
  6957.   tree typedef_decl = NULL_TREE;
  6958.   char *name;
  6959.   tree typedef_type = NULL_TREE;
  6960.   int funcdef_flag = 0;
  6961.   enum tree_code innermost_code = ERROR_MARK;
  6962.   int bitfield = 0;
  6963.   int size_varies = 0;
  6964.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  6965.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  6966.   tree init = NULL_TREE;
  6967.  
  6968.   /* Keep track of what sort of function is being processed
  6969.      so that we can warn about default return values, or explicit
  6970.      return values which do not match prescribed defaults.  */
  6971.   enum return_types return_type = return_normal;
  6972.  
  6973.   tree dname = NULL_TREE;
  6974.   tree ctype = current_class_type;
  6975.   tree ctor_return_type = NULL_TREE;
  6976.   enum overload_flags flags = NO_SPECIAL;
  6977.   tree quals = NULL_TREE;
  6978.  
  6979.   RIDBIT_RESET_ALL (specbits);
  6980.   if (decl_context == FUNCDEF)
  6981.     funcdef_flag = 1, decl_context = NORMAL;
  6982.   else if (decl_context == MEMFUNCDEF)
  6983.     funcdef_flag = -1, decl_context = FIELD;
  6984.   else if (decl_context == BITFIELD)
  6985.     bitfield = 1, decl_context = FIELD;
  6986.  
  6987.   if (flag_traditional && allocation_temporary_p ())
  6988.     end_temporary_allocation ();
  6989.  
  6990.   /* Look inside a declarator for the name being declared
  6991.      and get it as a string, for an error message.  */
  6992.   {
  6993.     tree last = NULL_TREE;
  6994.     register tree decl = declarator;
  6995.     name = NULL;
  6996.  
  6997.     while (decl)
  6998.       switch (TREE_CODE (decl))
  6999.         {
  7000.     case COND_EXPR:
  7001.       ctype = NULL_TREE;
  7002.       decl = TREE_OPERAND (decl, 0);
  7003.       break;
  7004.  
  7005.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  7006.       {
  7007.         tree name = TREE_OPERAND (decl, 0);
  7008.         tree rename = NULL_TREE;
  7009.  
  7010.         my_friendly_assert (flags == NO_SPECIAL, 152);
  7011.         flags = DTOR_FLAG;
  7012.         return_type = return_dtor;
  7013.         my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
  7014.         if (ctype == NULL_TREE)
  7015.           {
  7016.         if (current_class_type == NULL_TREE)
  7017.           {
  7018.             error ("destructors must be member functions");
  7019.             flags = NO_SPECIAL;
  7020.           }
  7021.         else
  7022.           {
  7023.             tree t = constructor_name (current_class_name);
  7024.             if (t != name)
  7025.               rename = t;
  7026.           }
  7027.           }
  7028.         else
  7029.           {
  7030.         tree t = constructor_name (ctype);
  7031.         if (t != name)
  7032.           rename = t;
  7033.           }
  7034.  
  7035.         if (rename)
  7036.           {
  7037.         error ("destructor `%s' must match class name `%s'",
  7038.                IDENTIFIER_POINTER (name),
  7039.                IDENTIFIER_POINTER (rename));
  7040.         TREE_OPERAND (decl, 0) = rename;
  7041.           }
  7042.         decl = name;
  7043.       }
  7044.       break;
  7045.  
  7046.     case ADDR_EXPR:         /* C++ reference declaration */
  7047.       /* fall through */
  7048.     case ARRAY_REF:
  7049.     case INDIRECT_REF:
  7050.       ctype = NULL_TREE;
  7051.       innermost_code = TREE_CODE (decl);
  7052.       last = decl;
  7053.       decl = TREE_OPERAND (decl, 0);
  7054.       break;
  7055.  
  7056.     case CALL_EXPR:
  7057.       if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  7058.         {
  7059.           /* This is actually a variable declaration using constructor
  7060.          syntax.  We need to call start_decl and finish_decl so we
  7061.          can get the variable initialized...  */
  7062.  
  7063.           if (last)
  7064.         /* We need to insinuate ourselves into the declarator in place
  7065.            of the CALL_EXPR.  */
  7066.         TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  7067.           else
  7068.         declarator = TREE_OPERAND (decl, 0);
  7069.  
  7070.           init = TREE_OPERAND (decl, 1);
  7071.  
  7072.           decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  7073.           finish_decl (decl, init, NULL_TREE, 1);
  7074.           return 0;
  7075.         }
  7076.       innermost_code = TREE_CODE (decl);
  7077.       decl = TREE_OPERAND (decl, 0);
  7078.       if (decl_context == FIELD && ctype == NULL_TREE)
  7079.         ctype = current_class_type;
  7080.       if (ctype != NULL_TREE
  7081.           && decl != NULL_TREE && flags != DTOR_FLAG
  7082.           && decl == constructor_name (ctype))
  7083.         {
  7084.           return_type = return_ctor;
  7085.           ctor_return_type = ctype;
  7086.         }
  7087.       ctype = NULL_TREE;
  7088.       break;
  7089.  
  7090.     case IDENTIFIER_NODE:
  7091.       dname = decl;
  7092.       decl = NULL_TREE;
  7093.  
  7094.       if (IDENTIFIER_OPNAME_P (dname))
  7095.         {
  7096.           if (IDENTIFIER_TYPENAME_P (dname))
  7097.         {
  7098.           my_friendly_assert (flags == NO_SPECIAL, 154);
  7099.           flags = TYPENAME_FLAG;
  7100.           ctor_return_type = TREE_TYPE (dname);
  7101.           return_type = return_conversion;
  7102.         }
  7103.           name = operator_name_string (dname);
  7104.         }
  7105.       else
  7106.         name = IDENTIFIER_POINTER (dname);
  7107.       break;
  7108.  
  7109.     case RECORD_TYPE:
  7110.     case UNION_TYPE:
  7111.     case ENUMERAL_TYPE:
  7112.       /* Parse error puts this typespec where
  7113.          a declarator should go.  */
  7114.       error ("declarator name missing");
  7115.       dname = TYPE_NAME (decl);
  7116.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  7117.         dname = DECL_NAME (dname);
  7118.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  7119.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  7120.       decl = NULL_TREE;
  7121.       break;
  7122.  
  7123.       /* C++ extension */
  7124.     case SCOPE_REF:
  7125.       {
  7126.         /* Perform error checking, and convert class names to types.
  7127.            We may call grokdeclarator multiple times for the same
  7128.            tree structure, so only do the conversion once.  In this
  7129.            case, we have exactly what we want for `ctype'.  */
  7130.         tree cname = TREE_OPERAND (decl, 0);
  7131.         if (cname == NULL_TREE)
  7132.           ctype = NULL_TREE;
  7133.         /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
  7134.         else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
  7135.              || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
  7136.           ctype = cname;
  7137.         else if (! is_aggr_typedef (cname, 1))
  7138.           {
  7139.         TREE_OPERAND (decl, 0) = NULL_TREE;
  7140.           }
  7141.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  7142.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  7143.         else if (TREE_OPERAND (decl, 1)
  7144.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  7145.           {
  7146.         TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
  7147.           }
  7148.         else if (ctype == NULL_TREE)
  7149.           {
  7150.         ctype = IDENTIFIER_TYPE_VALUE (cname);
  7151.         TREE_OPERAND (decl, 0) = ctype;
  7152.           }
  7153.         else if (TREE_COMPLEXITY (decl) == current_class_depth)
  7154.           TREE_OPERAND (decl, 0) = ctype;
  7155.         else
  7156.           {
  7157.         if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
  7158.                            ctype))
  7159.           {
  7160.             cp_error ("type `%T' is not derived from type `%T'",
  7161.                   IDENTIFIER_TYPE_VALUE (cname), ctype);
  7162.             TREE_OPERAND (decl, 0) = NULL_TREE;
  7163.           }
  7164.         else
  7165.           {
  7166.             ctype = IDENTIFIER_TYPE_VALUE (cname);
  7167.             TREE_OPERAND (decl, 0) = ctype;
  7168.           }
  7169.           }
  7170.  
  7171.         decl = TREE_OPERAND (decl, 1);
  7172.         if (ctype)
  7173.           {
  7174.         if (TREE_CODE (decl) == IDENTIFIER_NODE
  7175.             && constructor_name (ctype) == decl)
  7176.           {
  7177.             return_type = return_ctor;
  7178.             ctor_return_type = ctype;
  7179.           }
  7180.         else if (TREE_CODE (decl) == BIT_NOT_EXPR
  7181.              && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  7182.              && constructor_name (ctype) == TREE_OPERAND (decl, 0))
  7183.           {
  7184.             return_type = return_dtor;
  7185.             ctor_return_type = ctype;
  7186.             flags = DTOR_FLAG;
  7187.             decl = TREE_OPERAND (decl, 0);
  7188.           }
  7189.           }
  7190.       }
  7191.       break;
  7192.  
  7193.     case ERROR_MARK:
  7194.       decl = NULL_TREE;
  7195.       break;
  7196.  
  7197.     default:
  7198.       return 0; /* We used to do a 155 abort here.  */
  7199.     }
  7200.     if (name == NULL)
  7201.       name = "type name";
  7202.   }
  7203.  
  7204.   /* A function definition's declarator must have the form of
  7205.      a function declarator.  */
  7206.  
  7207.   if (funcdef_flag && innermost_code != CALL_EXPR)
  7208.     return 0;
  7209.  
  7210.   /* Anything declared one level down from the top level
  7211.      must be one of the parameters of a function
  7212.      (because the body is at least two levels down).  */
  7213.  
  7214.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  7215.      by not allowing C++ class definitions to specify their parameters
  7216.      with xdecls (must be spec.d in the parmlist).
  7217.  
  7218.      Since we now wait to push a class scope until we are sure that
  7219.      we are in a legitimate method context, we must set oldcname
  7220.      explicitly (since current_class_name is not yet alive).  */
  7221.  
  7222.   if (decl_context == NORMAL
  7223.       && current_binding_level->level_chain == global_binding_level)
  7224.     decl_context = PARM;
  7225.  
  7226.   /* Look through the decl specs and record which ones appear.
  7227.      Some typespecs are defined as built-in typenames.
  7228.      Others, the ones that are modifiers of other types,
  7229.      are represented by bits in SPECBITS: set the bits for
  7230.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  7231.  
  7232.      If there is a typedef name or a type, store the type in TYPE.
  7233.      This includes builtin typedefs such as `int'.
  7234.  
  7235.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  7236.      come from a user typedef.
  7237.  
  7238.      Set LONGLONG if `long' is mentioned twice.
  7239.  
  7240.      For C++, constructors and destructors have their own fast treatment.  */
  7241.  
  7242.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  7243.     {
  7244.       register int i;
  7245.       register tree id;
  7246.  
  7247.       /* Certain parse errors slip through.  For example,
  7248.      `int class;' is not caught by the parser. Try
  7249.      weakly to recover here.  */
  7250.       if (TREE_CODE (spec) != TREE_LIST)
  7251.     return 0;
  7252.  
  7253.       id = TREE_VALUE (spec);
  7254.  
  7255.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  7256.     {
  7257.       if (id == ridpointers[(int) RID_INT]
  7258.           || id == ridpointers[(int) RID_CHAR]
  7259.           || id == ridpointers[(int) RID_BOOL]
  7260.           || id == ridpointers[(int) RID_WCHAR])
  7261.         {
  7262.           if (type)
  7263.         error ("extraneous `%T' ignored", id);
  7264.           else
  7265.         {
  7266.           if (id == ridpointers[(int) RID_INT])
  7267.             explicit_int = 1;
  7268.           else if (id == ridpointers[(int) RID_CHAR])
  7269.             explicit_char = 1;
  7270.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7271.         }
  7272.           goto found;
  7273.         }
  7274.       /* C++ aggregate types. */
  7275.       if (IDENTIFIER_HAS_TYPE_VALUE (id))
  7276.         {
  7277.           if (type)
  7278.         cp_error ("multiple declarations `%T' and `%T'", type, id);
  7279.           else
  7280.         type = IDENTIFIER_TYPE_VALUE (id);
  7281.           goto found;
  7282.         }
  7283.  
  7284.       for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  7285.         {
  7286.           if (ridpointers[i] == id)
  7287.         {
  7288.           if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
  7289.             {
  7290.               if (pedantic && flag_ansi)
  7291.             pedwarn ("duplicate `long'");
  7292.               else if (longlong)
  7293.             error ("`long long long' is too long for GCC");
  7294.               else
  7295.             longlong = 1;
  7296.             }
  7297.           else if (RIDBIT_SETP (i, specbits))
  7298.             pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  7299.           RIDBIT_SET (i, specbits);
  7300.           goto found;
  7301.         }
  7302.         }
  7303.     }
  7304.       if (type)
  7305.     error ("two or more data types in declaration of `%s'", name);
  7306.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  7307.     {
  7308.       register tree t = lookup_name (id, 1);
  7309.       if (!t || TREE_CODE (t) != TYPE_DECL)
  7310.         error ("`%s' fails to be a typedef or built in type",
  7311.            IDENTIFIER_POINTER (id));
  7312.       else
  7313.         {
  7314.           type = TREE_TYPE (t);
  7315.           typedef_decl = t;
  7316.         }
  7317.     }
  7318.       else if (TREE_CODE (id) != ERROR_MARK)
  7319.     /* Can't change CLASS nodes into RECORD nodes here!  */
  7320.     type = id;
  7321.  
  7322.     found: ;
  7323.     }
  7324.  
  7325.   typedef_type = type;
  7326.  
  7327.   /* No type at all: default to `int', and set EXPLICIT_INT
  7328.      because it was not a user-defined typedef.
  7329.      Except when we have a `typedef' inside a signature, in
  7330.      which case the type defaults to `unknown type' and is
  7331.      instantiated when assigning to a signature pointer or ref.  */
  7332.  
  7333.   if (type == NULL_TREE
  7334.       && (RIDBIT_SETP (RID_SIGNED, specbits)
  7335.       || RIDBIT_SETP (RID_UNSIGNED, specbits)
  7336.       || RIDBIT_SETP (RID_LONG, specbits)
  7337.       || RIDBIT_SETP (RID_SHORT, specbits)))
  7338.     {
  7339.       /* These imply 'int'.  */
  7340.       type = integer_type_node;
  7341.       explicit_int = 1;
  7342.     }
  7343.  
  7344.   if (type == NULL_TREE)
  7345.     {
  7346.       explicit_int = -1;
  7347.       if (return_type == return_dtor)
  7348.     type = void_type_node;
  7349.       else if (return_type == return_ctor)
  7350.     type = TYPE_POINTER_TO (ctor_return_type);
  7351.       else if (return_type == return_conversion)
  7352.     type = ctor_return_type;
  7353.       else if (current_class_type
  7354.            && IS_SIGNATURE (current_class_type)
  7355.            && (RIDBIT_SETP (RID_TYPEDEF, specbits)
  7356.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  7357.            && (decl_context == FIELD || decl_context == NORMAL))
  7358.     {
  7359.       explicit_int = 0;
  7360.       opaque_typedef = 1;
  7361.       type = copy_node (opaque_type_node);
  7362.     }
  7363.       /* access declaration */
  7364.       else if (decl_context == FIELD && declarator
  7365.            && TREE_CODE (declarator) == SCOPE_REF)
  7366.     type = void_type_node;
  7367.       else
  7368.     {
  7369.       if (funcdef_flag)
  7370.         {
  7371.           if (warn_return_type
  7372.           && return_type == return_normal)
  7373.         /* Save warning until we know what is really going on.  */
  7374.         warn_about_return_type = 1;
  7375.         }
  7376.       else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  7377.         pedwarn ("ANSI C++ forbids typedef which does not specify a type");
  7378.       else if (declspecs == NULL_TREE &&
  7379.            (innermost_code != CALL_EXPR || pedantic))
  7380.         cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
  7381.             dname);
  7382.       type = integer_type_node;
  7383.     }
  7384.     }
  7385.   else if (return_type == return_dtor)
  7386.     {
  7387.       error ("return type specification for destructor invalid");
  7388.       type = void_type_node;
  7389.     }
  7390.   else if (return_type == return_ctor)
  7391.     {
  7392.       error ("return type specification for constructor invalid");
  7393.       type = TYPE_POINTER_TO (ctor_return_type);
  7394.     }
  7395.   else if (return_type == return_conversion)
  7396.     {
  7397.       if (comp_target_types (type, ctor_return_type, 1) == 0)
  7398.     cp_error ("operator `%T' declared to return `%T'",
  7399.           ctor_return_type, type);
  7400.       else
  7401.     cp_pedwarn ("return type specified for `operator %T'",
  7402.             ctor_return_type);
  7403.  
  7404.       type = ctor_return_type;
  7405.     }
  7406.   /* Catch typedefs that only specify a type, like 'typedef int;'.  */
  7407.   else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
  7408.     {
  7409.       /* Template "this is a type" syntax; just ignore for now.  */
  7410.       if (processing_template_defn)
  7411.     return void_type_node;
  7412.     }
  7413.  
  7414.   ctype = NULL_TREE;
  7415.  
  7416.   /* Now process the modifiers that were specified
  7417.      and check for invalid combinations.  */
  7418.  
  7419.   /* Long double is a special combination.  */
  7420.  
  7421.   if (RIDBIT_SETP (RID_LONG, specbits)
  7422.       && TYPE_MAIN_VARIANT (type) == double_type_node)
  7423.     {
  7424.       RIDBIT_RESET (RID_LONG, specbits);
  7425.       type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
  7426.                  TYPE_VOLATILE (type));
  7427.     }
  7428.  
  7429.   /* Check all other uses of type modifiers.  */
  7430.  
  7431.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  7432.       || RIDBIT_SETP (RID_SIGNED, specbits)
  7433.       || RIDBIT_SETP (RID_LONG, specbits)
  7434.       || RIDBIT_SETP (RID_SHORT, specbits))
  7435.     {
  7436.       int ok = 0;
  7437.  
  7438.       if (TREE_CODE (type) == REAL_TYPE)
  7439.     error ("short, signed or unsigned invalid for `%s'", name);
  7440.       else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
  7441.     error ("long, short, signed or unsigned invalid for `%s'", name);
  7442.       else if (RIDBIT_SETP (RID_LONG, specbits)
  7443.            && RIDBIT_SETP (RID_SHORT, specbits))
  7444.     error ("long and short specified together for `%s'", name);
  7445.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  7446.         || RIDBIT_SETP (RID_SHORT, specbits))
  7447.            && explicit_char)
  7448.     error ("long or short specified with char for `%s'", name);
  7449.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  7450.         || RIDBIT_SETP (RID_SHORT, specbits))
  7451.            && TREE_CODE (type) == REAL_TYPE)
  7452.     error ("long or short specified with floating type for `%s'", name);
  7453.       else if (RIDBIT_SETP (RID_SIGNED, specbits)
  7454.            && RIDBIT_SETP (RID_UNSIGNED, specbits))
  7455.     error ("signed and unsigned given together for `%s'", name);
  7456.       else
  7457.     {
  7458.       ok = 1;
  7459.       if (!explicit_int && !explicit_char && pedantic)
  7460.         {
  7461.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  7462.                name);
  7463.           if (flag_pedantic_errors)
  7464.         ok = 0;
  7465.         }
  7466.     }
  7467.  
  7468.       /* Discard the type modifiers if they are invalid.  */
  7469.       if (! ok)
  7470.     {
  7471.       RIDBIT_RESET (RID_UNSIGNED, specbits);
  7472.       RIDBIT_RESET (RID_SIGNED, specbits);
  7473.       RIDBIT_RESET (RID_LONG, specbits);
  7474.       RIDBIT_RESET (RID_SHORT, specbits);
  7475.       longlong = 0;
  7476.     }
  7477.     }
  7478.  
  7479.   /* Decide whether an integer type is signed or not.
  7480.      Optionally treat bitfields as signed by default.  */
  7481.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  7482.       /* Traditionally, all bitfields are unsigned.  */
  7483.       || (bitfield && flag_traditional)
  7484.       || (bitfield && ! flag_signed_bitfields
  7485.       && (explicit_int || explicit_char
  7486.           /* A typedef for plain `int' without `signed'
  7487.          can be controlled just like plain `int'.  */
  7488.           || ! (typedef_decl != NULL_TREE
  7489.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  7490.       && TREE_CODE (type) != ENUMERAL_TYPE
  7491.       && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
  7492.     {
  7493.       if (longlong)
  7494.     type = long_long_unsigned_type_node;
  7495.       else if (RIDBIT_SETP (RID_LONG, specbits))
  7496.     type = long_unsigned_type_node;
  7497.       else if (RIDBIT_SETP (RID_SHORT, specbits))
  7498.     type = short_unsigned_type_node;
  7499.       else if (type == char_type_node)
  7500.     type = unsigned_char_type_node;
  7501.       else if (typedef_decl)
  7502.     type = unsigned_type (type);
  7503.       else
  7504.     type = unsigned_type_node;
  7505.     }
  7506.   else if (RIDBIT_SETP (RID_SIGNED, specbits)
  7507.        && type == char_type_node)
  7508.     type = signed_char_type_node;
  7509.   else if (longlong)
  7510.     type = long_long_integer_type_node;
  7511.   else if (RIDBIT_SETP (RID_LONG, specbits))
  7512.     type = long_integer_type_node;
  7513.   else if (RIDBIT_SETP (RID_SHORT, specbits))
  7514.     type = short_integer_type_node;
  7515.  
  7516.   /* Set CONSTP if this declaration is `const', whether by
  7517.      explicit specification or via a typedef.
  7518.      Likewise for VOLATILEP.  */
  7519.  
  7520.   constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
  7521.   volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
  7522.   staticp = 0;
  7523.   inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
  7524.   if (constp > 1)
  7525.     warning ("duplicate `const'");
  7526.   if (volatilep > 1)
  7527.     warning ("duplicate `volatile'");
  7528.   virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
  7529.  
  7530.   if (RIDBIT_SETP (RID_STATIC, specbits))
  7531.     staticp = 1 + (decl_context == FIELD);
  7532.  
  7533.   if (virtualp && staticp == 2)
  7534.     {
  7535.       cp_error ("member `%D' cannot be declared both virtual and static",
  7536.         dname);
  7537.       staticp = 0;
  7538.     }
  7539.   friendp = RIDBIT_SETP (RID_FRIEND, specbits);
  7540.   RIDBIT_RESET (RID_VIRTUAL, specbits);
  7541.   RIDBIT_RESET (RID_FRIEND, specbits);
  7542.  
  7543.   if (RIDBIT_SETP (RID_MUTABLE, specbits))
  7544.     {
  7545.       if (decl_context == PARM)
  7546.     {
  7547.       error ("non-member `%s' cannot be declared mutable", name);
  7548.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7549.     }
  7550.       else if (friendp || decl_context == TYPENAME)
  7551.     {
  7552.       error ("non-object member `%s' cannot be declared mutable", name);
  7553.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7554.     }
  7555.       else if (staticp)
  7556.     {
  7557.       error ("static `%s' cannot be declared mutable", name);
  7558.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7559.     }
  7560. #if 0
  7561.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  7562.     {
  7563.       error ("non-object member `%s' cannot be declared mutable", name);
  7564.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7565.     }
  7566.       /* Because local typedefs are parsed twice, we don't want this
  7567.      message here. */
  7568.       else if (decl_context != FIELD)
  7569.     {
  7570.       error ("non-member `%s' cannot be declared mutable", name);
  7571.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7572.     }
  7573. #endif
  7574.     }
  7575.  
  7576.   /* Warn if two storage classes are given. Default to `auto'.  */
  7577.  
  7578.   if (RIDBIT_ANY_SET (specbits))
  7579.     {
  7580.       if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
  7581.       if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
  7582.       if (decl_context == PARM && nclasses > 0)
  7583.     error ("storage class specifiers invalid in parameter declarations");
  7584.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  7585.     {
  7586.       if (decl_context == PARM)
  7587.         error ("typedef declaration invalid in parameter declaration");
  7588.       nclasses++;
  7589.     }
  7590.       if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
  7591.       if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
  7592.     }
  7593.  
  7594.   /* Give error if `virtual' is used outside of class declaration.  */
  7595.   if (virtualp && current_class_name == NULL_TREE)
  7596.     {
  7597.       error ("virtual outside class declaration");
  7598.       virtualp = 0;
  7599.     }
  7600.   if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
  7601.     {
  7602.       error ("only members can be declared mutable");
  7603.       RIDBIT_RESET (RID_MUTABLE, specbits);
  7604.     }
  7605.  
  7606.   /* Static anonymous unions are dealt with here.  */
  7607.   if (staticp && decl_context == TYPENAME
  7608.       && TREE_CODE (declspecs) == TREE_LIST
  7609.       && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
  7610.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
  7611.     decl_context = FIELD;
  7612.  
  7613.   /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
  7614.      is used in a signature member function declaration.  */
  7615.   if (decl_context == FIELD
  7616.       && IS_SIGNATURE (current_class_type)
  7617.       && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
  7618.       && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  7619.     {
  7620.       if (constp)
  7621.     {
  7622.       error ("`const' specified for signature member function `%s'", name);
  7623.       constp = 0;
  7624.     }
  7625.       if (volatilep)
  7626.     {
  7627.       error ("`volatile' specified for signature member function `%s'",
  7628.          name);
  7629.       volatilep = 0;
  7630.     }
  7631.       if (inlinep)
  7632.     {
  7633.       error ("`inline' specified for signature member function `%s'", name);
  7634.       /* Later, we'll make signature member functions inline.  */
  7635.       inlinep = 0;
  7636.     }
  7637.       if (friendp)
  7638.     {
  7639.       error ("`friend' declaration in signature definition");
  7640.       friendp = 0;
  7641.     }
  7642.       if (virtualp)
  7643.     {
  7644.       error ("`virtual' specified for signature member function `%s'",
  7645.          name);
  7646.       /* Later, we'll make signature member functions virtual.  */
  7647.       virtualp = 0;
  7648.     }
  7649.     }
  7650.  
  7651.   /* Warn about storage classes that are invalid for certain
  7652.      kinds of declarations (parameters, typenames, etc.).  */
  7653.  
  7654.   if (nclasses > 1)
  7655.     error ("multiple storage classes in declaration of `%s'", name);
  7656.   else if (decl_context != NORMAL && nclasses > 0)
  7657.     {
  7658.       if (decl_context == PARM
  7659.       && (RIDBIT_SETP (RID_REGISTER, specbits)
  7660.           || RIDBIT_SETP (RID_AUTO, specbits)))
  7661.     ;
  7662.       else if (decl_context == FIELD
  7663.            && RIDBIT_SETP (RID_TYPEDEF, specbits))
  7664.     {
  7665.       /* Processing a typedef declaration nested within a class type
  7666.          definition.  */
  7667.       register tree scanner;
  7668.       register tree previous_declspec;
  7669.         tree loc_typedecl;
  7670.   
  7671.       if (initialized)
  7672.         error ("typedef declaration includes an initializer");
  7673.   
  7674.       /* To process a class-local typedef declaration, we descend down
  7675.          the chain of declspecs looking for the `typedef' spec.  When
  7676.          we find it, we replace it with `static', and then recursively
  7677.          call `grokdeclarator' with the original declarator and with
  7678.          the newly adjusted declspecs.  This call should return a
  7679.          FIELD_DECL node with the TREE_TYPE (and other parts) set
  7680.          appropriately.  We can then just change the TREE_CODE on that
  7681.          from FIELD_DECL to TYPE_DECL and we're done.  */
  7682.  
  7683.       for (previous_declspec = NULL_TREE, scanner = declspecs;
  7684.            scanner;
  7685.            previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
  7686.           {
  7687.           if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
  7688.         break;
  7689.           }
  7690.  
  7691.       if (scanner == IDENTIFIER_AS_LIST (ridpointers [(int) RID_TYPEDEF]))
  7692.         {
  7693.           if (previous_declspec)
  7694.         TREE_CHAIN (previous_declspec)
  7695.           = IDENTIFIER_AS_LIST (ridpointers [(int) RID_STATIC]);
  7696.           else
  7697.         declspecs
  7698.           = IDENTIFIER_AS_LIST (ridpointers [(int) RID_STATIC]);
  7699.         }
  7700.       else
  7701.         TREE_VALUE (scanner) = ridpointers[(int) RID_STATIC];
  7702.  
  7703.       /* In the recursive call to grokdeclarator we need to know
  7704.          whether we are working on a signature-local typedef.  */
  7705.       if (IS_SIGNATURE (current_class_type))
  7706.         SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
  7707.   
  7708.       loc_typedecl =
  7709.         grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
  7710.   
  7711.       if (loc_typedecl != error_mark_node)
  7712.           {
  7713.           register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  7714.           register int *pi;
  7715.   
  7716.           TREE_SET_CODE (loc_typedecl, TYPE_DECL);
  7717.   
  7718.           pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  7719.           while (i > 0)
  7720.             pi[--i] = 0;
  7721.           DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  7722.         }
  7723.   
  7724.       if (IS_SIGNATURE (current_class_type))
  7725.         {
  7726.           SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
  7727.           if (loc_typedecl != error_mark_node && opaque_typedef)
  7728.         SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
  7729.         }
  7730.  
  7731.         return loc_typedecl;
  7732.     }
  7733.       else if (decl_context == FIELD
  7734.            && (! IS_SIGNATURE (current_class_type)
  7735.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  7736.             /* C++ allows static class elements  */
  7737.             && RIDBIT_SETP (RID_STATIC, specbits))
  7738.      /* C++ also allows inlines and signed and unsigned elements,
  7739.         but in those cases we don't come in here.  */
  7740.     ;
  7741.       else
  7742.     {
  7743.       if (decl_context == FIELD)
  7744.         {
  7745.           tree tmp = TREE_OPERAND (declarator, 0);
  7746.           register int op = IDENTIFIER_OPNAME_P (tmp);
  7747.           error ("storage class specified for %s `%s'",
  7748.              IS_SIGNATURE (current_class_type)
  7749.              ? (op
  7750.             ? "signature member operator"
  7751.             : "signature member function")
  7752.              : (op ? "member operator" : "structure field"),
  7753.              op ? operator_name_string (tmp) : name);
  7754.         }
  7755.       else
  7756.         error ((decl_context == PARM
  7757.             ? "storage class specified for parameter `%s'"
  7758.             : "storage class specified for typename"), name);
  7759.       RIDBIT_RESET (RID_REGISTER, specbits);
  7760.       RIDBIT_RESET (RID_AUTO, specbits);
  7761.       RIDBIT_RESET (RID_EXTERN, specbits);
  7762.  
  7763.       if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
  7764.         {
  7765.           RIDBIT_RESET (RID_STATIC, specbits);
  7766.           staticp = 0;
  7767.         }
  7768.     }
  7769.     }
  7770.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
  7771.     {
  7772.       if (current_binding_level == global_binding_level)
  7773.     {
  7774.       /* It's common practice (and completely legal) to have a const
  7775.          be initialized and declared extern.  */
  7776.       if (! constp)
  7777.         warning ("`%s' initialized and declared `extern'", name);
  7778.     }
  7779.       else
  7780.     error ("`%s' has both `extern' and initializer", name);
  7781.     }
  7782.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
  7783.        && current_binding_level != global_binding_level)
  7784.     error ("nested function `%s' declared `extern'", name);
  7785.   else if (current_binding_level == global_binding_level)
  7786.     {
  7787.       if (RIDBIT_SETP (RID_AUTO, specbits))
  7788.     error ("top-level declaration of `%s' specifies `auto'", name);
  7789. #if 0
  7790.       if (RIDBIT_SETP (RID_REGISTER, specbits))
  7791.     error ("top-level declaration of `%s' specifies `register'", name);
  7792. #endif
  7793. #if 0
  7794.       /* I'm not sure under what circumstances we should turn
  7795.      on the extern bit, and under what circumstances we should
  7796.      warn if other bits are turned on.  */
  7797.       if (decl_context == NORMAL
  7798.       && RIDBIT_NOSETP (RID_EXTERN, specbits)
  7799.       && ! root_lang_context_p ())
  7800.     {
  7801.       RIDBIT_SET (RID_EXTERN, specbits);
  7802.     }
  7803. #endif
  7804.     }
  7805.  
  7806.   /* Now figure out the structure of the declarator proper.
  7807.      Descend through it, creating more complex types, until we reach
  7808.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  7809.  
  7810.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  7811.     {
  7812.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  7813.      an INDIRECT_REF (for *...),
  7814.      a CALL_EXPR (for ...(...)),
  7815.      an identifier (for the name being declared)
  7816.      or a null pointer (for the place in an absolute declarator
  7817.      where the name was omitted).
  7818.      For the last two cases, we have just exited the loop.
  7819.  
  7820.      For C++ it could also be
  7821.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  7822.      sensible names to types, and those are the values we use to
  7823.      qualify the member name.
  7824.      an ADDR_EXPR (for &...),
  7825.      a BIT_NOT_EXPR (for destructors)
  7826.  
  7827.      At this point, TYPE is the type of elements of an array,
  7828.      or for a function to return, or for a pointer to point to.
  7829.      After this sequence of ifs, TYPE is the type of the
  7830.      array or function or pointer, and DECLARATOR has had its
  7831.      outermost layer removed.  */
  7832.  
  7833.       if (TREE_CODE (type) == ERROR_MARK)
  7834.     {
  7835.       if (TREE_CODE (declarator) == SCOPE_REF)
  7836.         declarator = TREE_OPERAND (declarator, 1);
  7837.       else
  7838.         declarator = TREE_OPERAND (declarator, 0);
  7839.       continue;
  7840.     }
  7841.       if (quals != NULL_TREE
  7842.       && (declarator == NULL_TREE
  7843.           || TREE_CODE (declarator) != SCOPE_REF))
  7844.     {
  7845.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  7846.         ctype = TYPE_METHOD_BASETYPE (type);
  7847.       if (ctype != NULL_TREE)
  7848.         {
  7849. #if 0 /* not yet, should get fixed properly later */
  7850.           tree dummy = make_type_decl (NULL_TREE, type);
  7851. #else
  7852.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  7853. #endif
  7854.           ctype = grok_method_quals (ctype, dummy, quals);
  7855.           type = TREE_TYPE (dummy);
  7856.           quals = NULL_TREE;
  7857.         }
  7858.     }
  7859.       switch (TREE_CODE (declarator))
  7860.     {
  7861.     case ARRAY_REF:
  7862.       {
  7863.         register tree itype = NULL_TREE;
  7864.         register tree size = TREE_OPERAND (declarator, 1);
  7865.  
  7866.         declarator = TREE_OPERAND (declarator, 0);
  7867.  
  7868.         /* Check for some types that there cannot be arrays of.  */
  7869.  
  7870.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  7871.           {
  7872.         cp_error ("declaration of `%D' as array of voids", dname);
  7873.         type = error_mark_node;
  7874.           }
  7875.  
  7876.         if (TREE_CODE (type) == FUNCTION_TYPE)
  7877.           {
  7878.         cp_error ("declaration of `%D' as array of functions", dname);
  7879.         type = error_mark_node;
  7880.           }
  7881.  
  7882.         /* ARM $8.4.3: Since you can't have a pointer to a reference,
  7883.            you can't have arrays of references.  If we allowed them,
  7884.            then we'd be saying x[i] is legal for an array x, but
  7885.            then you'd have to ask: what does `*(x + i)' mean?  */
  7886.         if (TREE_CODE (type) == REFERENCE_TYPE)
  7887.           {
  7888.         if (decl_context == TYPENAME)
  7889.           cp_error ("cannot make arrays of references");
  7890.         else
  7891.           cp_error ("declaration of `%D' as array of references",
  7892.                 dname);
  7893.         type = error_mark_node;
  7894.           }
  7895.  
  7896.         if (TREE_CODE (type) == OFFSET_TYPE)
  7897.           {
  7898.           cp_error ("declaration of `%D' as array of data members",
  7899.                 dname);
  7900.         type = error_mark_node;
  7901.           }
  7902.  
  7903.         if (TREE_CODE (type) == METHOD_TYPE)
  7904.           {
  7905.         cp_error ("declaration of `%D' as array of function members",
  7906.               dname);
  7907.         type = error_mark_node;
  7908.           }
  7909.  
  7910.         if (size == error_mark_node)
  7911.           type = error_mark_node;
  7912.  
  7913.         if (type == error_mark_node)
  7914.           continue;
  7915.  
  7916.         if (size)
  7917.           {
  7918.         /* Must suspend_momentary here because the index
  7919.            type may need to live until the end of the function.
  7920.            For example, it is used in the declaration of a
  7921.            variable which requires destructing at the end of
  7922.            the function; then build_vec_delete will need this
  7923.            value.  */
  7924.         int yes = suspend_momentary ();
  7925.         /* might be a cast */
  7926.         if (TREE_CODE (size) == NOP_EXPR
  7927.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  7928.           size = TREE_OPERAND (size, 0);
  7929.  
  7930.         /* If this is a template parameter, it'll be constant, but
  7931.            we don't know what the value is yet.  */
  7932.         if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
  7933.           goto dont_grok_size;
  7934.  
  7935.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  7936.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  7937.           {
  7938.             cp_error ("size of array `%D' has non-integer type",
  7939.                   dname);
  7940.             size = integer_one_node;
  7941.           }
  7942.         if (TREE_READONLY_DECL_P (size))
  7943.           size = decl_constant_value (size);
  7944.         if (flag_ansi && integer_zerop (size))
  7945.           cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
  7946.         if (TREE_CONSTANT (size))
  7947.           {
  7948.             constant_expression_warning (size);
  7949.             if (INT_CST_LT (size, integer_zero_node))
  7950.               {
  7951.             cp_error ("size of array `%D' is negative", dname);
  7952.             size = integer_one_node;
  7953.               }
  7954.             itype = build_index_type (size_binop (MINUS_EXPR, size,
  7955.                               integer_one_node));
  7956.           }
  7957.         else
  7958.           {
  7959.             if (flag_ansi)
  7960.               {
  7961.             if (dname)
  7962.               cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
  7963.                       dname);
  7964.             else
  7965.               cp_pedwarn ("ANSI C++ forbids variable-size array");
  7966.               }
  7967.           dont_grok_size:
  7968.             itype =
  7969.               build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
  7970.             /* Make sure the array size remains visibly nonconstant
  7971.                even if it is (eg) a const variable with known value.  */
  7972.             size_varies = 1;
  7973.             itype = variable_size (itype);
  7974.             itype = build_index_type (itype);
  7975.           }
  7976.         resume_momentary (yes);
  7977.           }
  7978.  
  7979.       /* Build the array type itself, then merge any constancy or
  7980.          volatility into the target type.  We must do it in this order
  7981.          to ensure that the TYPE_MAIN_VARIANT field of the array type
  7982.          is set correctly.  */
  7983.  
  7984.         type = build_cplus_array_type (type, itype);
  7985.         if (constp || volatilep)
  7986.           type = c_build_type_variant (type, constp, volatilep);
  7987.  
  7988.         ctype = NULL_TREE;
  7989.       }
  7990.       break;
  7991.  
  7992.     case CALL_EXPR:
  7993.       {
  7994.         tree arg_types;
  7995.  
  7996.         /* Declaring a function type.
  7997.            Make sure we have a valid type for the function to return.  */
  7998. #if 0
  7999.         /* Is this an error?  Should they be merged into TYPE here?  */
  8000.         if (pedantic && (constp || volatilep))
  8001.           pedwarn ("function declared to return const or volatile result");
  8002. #else
  8003.         /* Merge any constancy or volatility into the function return
  8004.                type.  */
  8005.  
  8006.         if (constp || volatilep)
  8007.           {
  8008.         type = c_build_type_variant (type, constp, volatilep);
  8009.         if (IS_AGGR_TYPE (type))
  8010.           build_pointer_type (type);
  8011.         constp = 0;
  8012.         volatilep = 0;
  8013.           }
  8014. #endif
  8015.  
  8016.         /* Warn about some types functions can't return.  */
  8017.  
  8018.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8019.           {
  8020.         error ("`%s' declared as function returning a function", name);
  8021.         type = integer_type_node;
  8022.           }
  8023.         if (TREE_CODE (type) == ARRAY_TYPE)
  8024.           {
  8025.         error ("`%s' declared as function returning an array", name);
  8026.         type = integer_type_node;
  8027.           }
  8028.  
  8029.         if (ctype == NULL_TREE
  8030.         && decl_context == FIELD
  8031.         && (friendp == 0 || dname == current_class_name))
  8032.           ctype = current_class_type;
  8033.  
  8034.         if (ctype && return_type == return_conversion)
  8035.           TYPE_HAS_CONVERSION (ctype) = 1;
  8036.         if (ctype && constructor_name (ctype) == dname)
  8037.           {
  8038.         /* We are within a class's scope. If our declarator name
  8039.            is the same as the class name, and we are defining
  8040.            a function, then it is a constructor/destructor, and
  8041.            therefore returns a void type.  */
  8042.  
  8043.         if (flags == DTOR_FLAG)
  8044.           {
  8045.             /* ANSI C++ June 5 1992 WP 12.4.1.  A destructor may
  8046.                not be declared const or volatile.  A destructor
  8047.                may not be static.  */
  8048.             if (staticp == 2)
  8049.               error ("destructor cannot be static member function");
  8050.             if (TYPE_READONLY (type))
  8051.               {
  8052.             error ("destructors cannot be declared `const'");
  8053.             return void_type_node;
  8054.               }
  8055.             if (TYPE_VOLATILE (type))
  8056.               {
  8057.             error ("destructors cannot be declared `volatile'");
  8058.             return void_type_node;
  8059.               }
  8060.             if (decl_context == FIELD)
  8061.               {
  8062.             if (! member_function_or_else (ctype, current_class_type,
  8063.                                "destructor for alien class `%s' cannot be a member"))
  8064.               return void_type_node;
  8065.               }
  8066.           }
  8067.         else            /* it's a constructor. */
  8068.           {
  8069.             /* ANSI C++ June 5 1992 WP 12.1.2.  A constructor may
  8070.                not be declared const or volatile.  A constructor may
  8071.                not be virtual.  A constructor may not be static.  */
  8072.             if (staticp == 2)
  8073.               error ("constructor cannot be static member function");
  8074.             if (virtualp)
  8075.               {
  8076.             pedwarn ("constructors cannot be declared virtual");
  8077.             virtualp = 0;
  8078.               }
  8079.             if (TYPE_READONLY (type))
  8080.               {
  8081.             error ("constructors cannot be declared `const'");
  8082.             return void_type_node;
  8083.                }
  8084.             if (TYPE_VOLATILE (type))
  8085.               {
  8086.             error ("constructors cannot be declared `volatile'");
  8087.             return void_type_node;
  8088.               }
  8089.             {
  8090.               RID_BIT_TYPE tmp_bits;
  8091.               bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
  8092.               RIDBIT_RESET (RID_INLINE, tmp_bits);
  8093.               RIDBIT_RESET (RID_STATIC, tmp_bits);
  8094.               if (RIDBIT_ANY_SET (tmp_bits))
  8095.             error ("return value type specifier for constructor ignored");
  8096.             }
  8097.             type = TYPE_POINTER_TO (ctype);
  8098.             if (decl_context == FIELD &&
  8099.             IS_SIGNATURE (current_class_type))
  8100.               {
  8101.             error ("constructor not allowed in signature");
  8102.             return void_type_node;
  8103.               }              
  8104.             else if (decl_context == FIELD)
  8105.               {
  8106.             if (! member_function_or_else (ctype, current_class_type,
  8107.                                "constructor for alien class `%s' cannot be member"))
  8108.               return void_type_node;
  8109.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  8110.             if (return_type != return_ctor)
  8111.               return NULL_TREE;
  8112.               }
  8113.           }
  8114.         if (decl_context == FIELD)
  8115.           staticp = 0;
  8116.           }
  8117.         else if (friendp && virtualp)
  8118.           {
  8119.         /* Cannot be both friend and virtual.  */
  8120.         error ("virtual functions cannot be friends");
  8121.         RIDBIT_RESET (RID_FRIEND, specbits);
  8122.         friendp = 0;
  8123.           }
  8124.  
  8125.         if (decl_context == NORMAL && friendp)
  8126.           error ("friend declaration not in class definition");
  8127.  
  8128.         /* Pick up type qualifiers which should be applied to `this'.  */
  8129.         quals = TREE_OPERAND (declarator, 2);
  8130.  
  8131.         /* Traditionally, declaring return type float means double.  */
  8132.  
  8133.         if (flag_traditional
  8134.         && TYPE_MAIN_VARIANT (type) == float_type_node)
  8135.           {
  8136.         type = build_type_variant (double_type_node,
  8137.                        TYPE_READONLY (type),
  8138.                        TYPE_VOLATILE (type));
  8139.           }
  8140.  
  8141.         /* Construct the function type and go to the next
  8142.            inner layer of declarator.  */
  8143.  
  8144.         {
  8145.           int funcdef_p;
  8146.           tree inner_parms = TREE_OPERAND (declarator, 1);
  8147.           tree inner_decl = TREE_OPERAND (declarator, 0);
  8148.  
  8149.           declarator = TREE_OPERAND (declarator, 0);
  8150.  
  8151.           if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  8152.         inner_decl = TREE_OPERAND (inner_decl, 1);
  8153.  
  8154.           /* Say it's a definition only for the CALL_EXPR
  8155.          closest to the identifier.  */
  8156.           funcdef_p =
  8157.         (inner_decl && TREE_CODE (inner_decl) == IDENTIFIER_NODE)
  8158.           ? funcdef_flag : 0;
  8159.  
  8160.           /* FIXME: This is where default args should be fully
  8161.          processed.  */
  8162.  
  8163.           arg_types = grokparms (inner_parms, funcdef_p);
  8164.         }
  8165.  
  8166.         if (declarator)
  8167.           {
  8168.         /* Get past destructors, etc.
  8169.            We know we have one because FLAGS will be non-zero.
  8170.  
  8171.            Complain about improper parameter lists here.  */
  8172.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  8173.           {
  8174.             declarator = TREE_OPERAND (declarator, 0);
  8175.  
  8176.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  8177.               arg_types = void_list_node;
  8178.             else if (arg_types == NULL_TREE
  8179.                  || arg_types != void_list_node)
  8180.               {
  8181.             error ("destructors cannot be specified with parameters");
  8182.             arg_types = void_list_node;
  8183.               }
  8184.           }
  8185.           }
  8186.  
  8187.         /* ANSI seems to say that `const int foo ();'
  8188.            does not make the function foo const.  */
  8189.         type = build_function_type (type,
  8190.                     flag_traditional ? 0 : arg_types);
  8191.       }
  8192.       break;
  8193.  
  8194.     case ADDR_EXPR:
  8195.     case INDIRECT_REF:
  8196.       /* Filter out pointers-to-references and references-to-references.
  8197.          We can get these if a TYPE_DECL is used.  */
  8198.  
  8199.       if (TREE_CODE (type) == REFERENCE_TYPE)
  8200.         {
  8201.           error ("cannot declare %s to references",
  8202.              TREE_CODE (declarator) == ADDR_EXPR
  8203.              ? "references" : "pointers");
  8204.           declarator = TREE_OPERAND (declarator, 0);
  8205.           continue;
  8206.         }
  8207.  
  8208.       /* Merge any constancy or volatility into the target type
  8209.          for the pointer.  */
  8210.  
  8211.       if (constp || volatilep)
  8212.         {
  8213.           /* A const or volatile signature pointer/reference is
  8214.          pointing to a const or volatile object, i.e., the
  8215.          `optr' is const or volatile, respectively, not the
  8216.          signature pointer/reference itself.  */
  8217.           if (! IS_SIGNATURE (type))
  8218.         {
  8219.           type = c_build_type_variant (type, constp, volatilep);
  8220.           if (IS_AGGR_TYPE (type))
  8221.             build_pointer_type (type);
  8222.           constp = 0;
  8223.           volatilep = 0;
  8224.         }
  8225.         }
  8226.  
  8227.       if (IS_SIGNATURE (type))
  8228.         {
  8229.           if (TREE_CODE (declarator) == ADDR_EXPR)
  8230.         {
  8231.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8232.               && TYPE_SIZE (type))
  8233.             cp_warning ("empty signature `%T' used in signature reference declaration",
  8234.                 type);
  8235. #if 0
  8236.           type = build_signature_reference_type (type,
  8237.                              constp, volatilep);
  8238. #else
  8239.           sorry ("signature reference");
  8240.           return NULL_TREE;
  8241. #endif
  8242.         }
  8243.           else
  8244.         {
  8245.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8246.               && TYPE_SIZE (type))
  8247.             cp_warning ("empty signature `%T' used in signature pointer declaration",
  8248.                 type);
  8249.           type = build_signature_pointer_type (type,
  8250.                                constp, volatilep);
  8251.         }
  8252.           constp = 0;
  8253.           volatilep = 0;
  8254.         }
  8255.       else if (TREE_CODE (declarator) == ADDR_EXPR)
  8256.         {
  8257.           if (TREE_CODE (type) == FUNCTION_TYPE)
  8258.         {
  8259.           error ("cannot declare references to functions; use pointer to function instead");
  8260.           type = build_pointer_type (type);
  8261.         }
  8262.           else
  8263.         {
  8264.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8265.             error ("invalid type: `void &'");
  8266.           else
  8267.             type = build_reference_type (type);
  8268.         }
  8269.         }
  8270.       else if (TREE_CODE (type) == METHOD_TYPE)
  8271.         {
  8272.           type = build_ptrmemfunc_type (build_pointer_type (type));
  8273.         }
  8274.       else
  8275.         type = build_pointer_type (type);
  8276.  
  8277.       /* Process a list of type modifier keywords (such as
  8278.          const or volatile) that were given inside the `*' or `&'.  */
  8279.  
  8280.       if (TREE_TYPE (declarator))
  8281.         {
  8282.           register tree typemodlist;
  8283.           int erred = 0;
  8284.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  8285.            typemodlist = TREE_CHAIN (typemodlist))
  8286.         {
  8287.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  8288.             constp++;
  8289.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  8290.             volatilep++;
  8291.           else if (!erred)
  8292.             {
  8293.               erred = 1;
  8294.               error ("invalid type modifier within %s declarator",
  8295.                  TREE_CODE (declarator) == ADDR_EXPR
  8296.                  ? "reference" : "pointer");
  8297.             }
  8298.         }
  8299.           if (constp > 1)
  8300.         pedwarn ("duplicate `const'");
  8301.           if (volatilep > 1)
  8302.         pedwarn ("duplicate `volatile'");
  8303.           if (TREE_CODE (declarator) == ADDR_EXPR
  8304.           && (constp || volatilep))
  8305.         {
  8306.           if (constp)
  8307.             warning ("discarding `const' applied to a reference");
  8308.           if (volatilep)
  8309.             warning ("discarding `volatile' applied to a reference");
  8310.           constp = volatilep = 0;
  8311.         }
  8312.         }
  8313.       declarator = TREE_OPERAND (declarator, 0);
  8314.       ctype = NULL_TREE;
  8315.       break;
  8316.  
  8317.     case SCOPE_REF:
  8318.       {
  8319.         /* We have converted type names to NULL_TREE if the
  8320.            name was bogus, or to a _TYPE node, if not.
  8321.  
  8322.            The variable CTYPE holds the type we will ultimately
  8323.            resolve to.  The code here just needs to build
  8324.            up appropriate member types.  */
  8325.         tree sname = TREE_OPERAND (declarator, 1);
  8326.         /* Destructors can have their visibilities changed as well.  */
  8327.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  8328.           sname = TREE_OPERAND (sname, 0);
  8329.  
  8330.         if (TREE_COMPLEXITY (declarator) == 0)
  8331.           /* This needs to be here, in case we are called
  8332.          multiple times.  */ ;
  8333.         else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
  8334.           /* don't fall out into global scope. Hides real bug? --eichin */ ;
  8335.         else if (TREE_COMPLEXITY (declarator) == current_class_depth)
  8336.           {
  8337.         /* This pop_nested_class corresponds to the
  8338.                    push_nested_class used to push into class scope for
  8339.                    parsing the argument list of a function decl, in
  8340.                    qualified_id.  */
  8341.         pop_nested_class (1);
  8342.         TREE_COMPLEXITY (declarator) = current_class_depth;
  8343.           }
  8344.         else
  8345.           my_friendly_abort (16);
  8346.  
  8347.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  8348.           {
  8349.         /* We had a reference to a global decl, or
  8350.            perhaps we were given a non-aggregate typedef,
  8351.            in which case we cleared this out, and should just
  8352.            keep going as though it wasn't there.  */
  8353.         declarator = sname;
  8354.         continue;
  8355.           }
  8356.         ctype = TREE_OPERAND (declarator, 0);
  8357.  
  8358.         if (sname == NULL_TREE)
  8359.           goto done_scoping;
  8360.  
  8361.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  8362.           {
  8363.         /* This is the `standard' use of the scoping operator:
  8364.            basetype :: member .  */
  8365.  
  8366.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8367.           {
  8368.             if (current_class_type == NULL_TREE
  8369.             || TYPE_MAIN_VARIANT (ctype) == current_class_type
  8370.             || friendp)
  8371.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8372.                               TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8373.             else
  8374.               {
  8375.             cp_error ("cannot declare member function `%T::%s' within `%T'",
  8376.                   ctype, name, current_class_type);
  8377.             return void_type_node;
  8378.               }
  8379.           }
  8380.         else if (TYPE_MAIN_VARIANT (ctype) == current_class_type)
  8381.           {
  8382.             if (extra_warnings)
  8383.               cp_warning ("redundant qualification `%T' on member `%s' ignored",
  8384.                   ctype, name);
  8385.             type = build_offset_type (ctype, type);
  8386.           }
  8387.         else if (TYPE_SIZE (ctype) != NULL_TREE
  8388.              || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
  8389.           {
  8390.             tree t;
  8391.             /* have to move this code elsewhere in this function.
  8392.                this code is used for i.e., typedef int A::M; M *pm; */
  8393.  
  8394.             if (explicit_int == -1 && decl_context == FIELD
  8395.             && funcdef_flag == 0)
  8396.               {
  8397.             /* The code in here should only be used to build
  8398.                stuff that will be grokked as access decls.  */
  8399.             t = lookup_field (ctype, sname, 0, 0);
  8400.             if (t)
  8401.               {
  8402.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  8403.                 DECL_INITIAL (t) = init;
  8404.                 return t;
  8405.               }
  8406.             /* No such field, try member functions.  */
  8407.             t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
  8408.             if (t)
  8409.               {
  8410.                 if (flags == DTOR_FLAG)
  8411.                   t = TREE_VALUE (t);
  8412.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  8413.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  8414.                   {
  8415.                 /* Don't include destructor with constructors.  */
  8416.                 t = DECL_CHAIN (TREE_VALUE (t));
  8417.                 if (t == NULL_TREE)
  8418.                   error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
  8419.                 t = build_tree_list (NULL_TREE, t);
  8420.                   }
  8421.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  8422.                 DECL_INITIAL (t) = init;
  8423.                 return t;
  8424.               }
  8425.  
  8426.             cp_error
  8427.               ("field `%D' is not a member of structure `%T'",
  8428.                sname, ctype);
  8429.               }
  8430.  
  8431.             if (current_class_type)
  8432.               {
  8433.             if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
  8434.               {
  8435.                 cp_error ("cannot declare member `%T::%s' within `%T'",
  8436.                    ctype, name, current_class_type);
  8437.                 return void_type_node;
  8438.               }
  8439.             else if (extra_warnings)
  8440.               cp_warning ("extra qualification `%T' on member `%s' ignored",
  8441.                    ctype, name);
  8442.               }
  8443.             type = build_offset_type (ctype, type);
  8444.           }
  8445.         else if (uses_template_parms (ctype))
  8446.           {
  8447.                     enum tree_code c;
  8448.                     if (TREE_CODE (type) == FUNCTION_TYPE)
  8449.               {
  8450.             type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8451.                             TREE_TYPE (type),
  8452.                             TYPE_ARG_TYPES (type));
  8453.             c = FUNCTION_DECL;
  8454.               }
  8455.             }
  8456.         else
  8457.           {
  8458.             cp_error ("structure `%T' not yet defined", ctype);
  8459.             return error_mark_node;
  8460.           }
  8461.  
  8462.         declarator = sname;
  8463.           }
  8464.         else if (TREE_CODE (sname) == SCOPE_REF)
  8465.           my_friendly_abort (17);
  8466.         else
  8467.           {
  8468.           done_scoping:
  8469.         declarator = TREE_OPERAND (declarator, 1);
  8470.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  8471.           /* In this case, we will deal with it later.  */
  8472.           ;
  8473.         else
  8474.           {
  8475.             if (TREE_CODE (type) == FUNCTION_TYPE)
  8476.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8477.             else
  8478.               type = build_offset_type (ctype, type);
  8479.           }
  8480.           }
  8481.       }
  8482.       break;
  8483.  
  8484.     case BIT_NOT_EXPR:
  8485.       declarator = TREE_OPERAND (declarator, 0);
  8486.       break;
  8487.  
  8488.     case RECORD_TYPE:
  8489.     case UNION_TYPE:
  8490.     case ENUMERAL_TYPE:
  8491.       declarator = NULL_TREE;
  8492.       break;
  8493.  
  8494.     case ERROR_MARK:
  8495.       declarator = NULL_TREE;
  8496.       break;
  8497.  
  8498.     default:
  8499.       my_friendly_abort (158);
  8500.     }
  8501.     }
  8502.  
  8503.   /* Now TYPE has the actual type.  */
  8504.  
  8505.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  8506.  
  8507.   if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8508.     {
  8509.       tree decl;
  8510.  
  8511.       /* Note that the grammar rejects storage classes
  8512.      in typenames, fields or parameters.  */
  8513.       if (constp || volatilep)
  8514.     type = c_build_type_variant (type, constp, volatilep);
  8515.  
  8516.       /* If the user declares "struct {...} foo" then `foo' will have
  8517.      an anonymous name.  Fill that name in now.  Nothing can
  8518.      refer to it, so nothing needs know about the name change.
  8519.      The TYPE_NAME field was filled in by build_struct_xref.  */
  8520.       if (type != error_mark_node
  8521.       && TYPE_NAME (type)
  8522.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  8523.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
  8524.     {
  8525.       /* replace the anonymous name with the real name everywhere.  */
  8526.       lookup_tag_reverse (type, declarator);
  8527.       TYPE_IDENTIFIER (type) = declarator;
  8528.  
  8529.       if (TYPE_LANG_SPECIFIC (type))
  8530.         TYPE_WAS_ANONYMOUS (type) = 1;
  8531.  
  8532.       {
  8533.         tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
  8534.  
  8535.         if (!c)
  8536.           set_nested_typename (d, 0, declarator, type);
  8537.         else if (TREE_CODE (c) == FUNCTION_DECL)
  8538.           set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
  8539.                    declarator, type);
  8540.         else
  8541.           set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
  8542.       }
  8543.     }
  8544.  
  8545. #if 0 /* not yet, should get fixed properly later */
  8546.       decl = make_type_decl (declarator, type);
  8547. #else
  8548.       decl = build_decl (TYPE_DECL, declarator, type);
  8549. #endif
  8550.       if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
  8551.     {
  8552.       cp_error_at ("typedef name may not be class-qualified", decl);
  8553.       return NULL_TREE;
  8554.     }
  8555.       else if (quals)
  8556.     {
  8557.       if (ctype == NULL_TREE)
  8558.         {
  8559.           if (TREE_CODE (type) != METHOD_TYPE)
  8560.         cp_error_at ("invalid type qualifier for non-method type", decl);
  8561.           else
  8562.         ctype = TYPE_METHOD_BASETYPE (type);
  8563.         }
  8564.       if (ctype != NULL_TREE)
  8565.         grok_method_quals (ctype, decl, quals);
  8566.     }
  8567.  
  8568.       if (RIDBIT_SETP (RID_SIGNED, specbits)
  8569.       || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  8570.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  8571.  
  8572.       if (RIDBIT_SETP (RID_MUTABLE, specbits))
  8573.     {
  8574.       error ("non-object member `%s' cannot be declared mutable", name);
  8575.     }
  8576.  
  8577.       return decl;
  8578.     }
  8579.  
  8580.   /* Detect the case of an array type of unspecified size
  8581.      which came, as such, direct from a typedef name.
  8582.      We must copy the type, so that each identifier gets
  8583.      a distinct type, so that each identifier's size can be
  8584.      controlled separately by its own initializer.  */
  8585.  
  8586.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  8587.       && TYPE_DOMAIN (type) == NULL_TREE)
  8588.     {
  8589.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  8590.     }
  8591.  
  8592.   /* If this is a type name (such as, in a cast or sizeof),
  8593.      compute the type and return it now.  */
  8594.  
  8595.   if (decl_context == TYPENAME)
  8596.     {
  8597.       /* Note that the grammar rejects storage classes
  8598.      in typenames, fields or parameters.  */
  8599.       if (constp || volatilep)
  8600.     if (IS_SIGNATURE (type))
  8601.       error ("`const' or `volatile' specified with signature type");
  8602.     else  
  8603.       type = c_build_type_variant (type, constp, volatilep);
  8604.  
  8605.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  8606.       if (friendp)
  8607.     {
  8608.       /* A friendly class?  */
  8609.       if (current_class_type)
  8610.         make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  8611.       else
  8612.         error("trying to make class `%s' a friend of global scope",
  8613.           TYPE_NAME_STRING (type));
  8614.       type = void_type_node;
  8615.     }
  8616.       else if (quals)
  8617.     {
  8618. #if 0 /* not yet, should get fixed properly later */
  8619.       tree dummy = make_type_decl (declarator, type);
  8620. #else
  8621.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  8622. #endif
  8623.       if (ctype == NULL_TREE)
  8624.         {
  8625.           my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
  8626.           ctype = TYPE_METHOD_BASETYPE (type);
  8627.         }
  8628.       grok_method_quals (ctype, dummy, quals);
  8629.       type = TREE_TYPE (dummy);
  8630.     }
  8631.  
  8632.       return type;
  8633.     }
  8634.   else if (declarator == NULL_TREE && decl_context != PARM
  8635.        && TREE_CODE (type) != UNION_TYPE
  8636.        && ! bitfield)
  8637.     {
  8638.       cp_error ("abstract declarator `%T' used as declaration", type);
  8639.       declarator = make_anon_name ();
  8640.     }
  8641.  
  8642.   /* `void' at top level (not within pointer)
  8643.      is allowed only in typedefs or type names.
  8644.      We don't complain about parms either, but that is because
  8645.      a better error message can be made later.  */
  8646.  
  8647.   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
  8648.     {
  8649.       if (TREE_CODE (declarator) == IDENTIFIER_NODE)
  8650.     {
  8651.       if (IDENTIFIER_OPNAME_P (declarator))
  8652. #if 0                /* How could this happen? */
  8653.         error ("operator `%s' declared void",
  8654.            operator_name_string (declarator));
  8655. #else
  8656.         my_friendly_abort (356);
  8657. #endif
  8658.       else
  8659.         error ("variable or field `%s' declared void", name);
  8660.     }
  8661.       else
  8662.     error ("variable or field declared void");
  8663.       type = integer_type_node;
  8664.     }
  8665.  
  8666.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  8667.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  8668.  
  8669.   {
  8670.     register tree decl;
  8671.  
  8672.     if (decl_context == PARM)
  8673.       {
  8674.     if (ctype)
  8675.       error ("cannot use `::' in parameter declaration");
  8676.  
  8677.     /* A parameter declared as an array of T is really a pointer to T.
  8678.        One declared as a function is really a pointer to a function.
  8679.        One declared as a member is really a pointer to member.  */
  8680.  
  8681.     if (TREE_CODE (type) == ARRAY_TYPE)
  8682.       {
  8683.         /* Transfer const-ness of array into that of type pointed to. */
  8684.         type = build_pointer_type
  8685.           (c_build_type_variant (TREE_TYPE (type), constp, volatilep));
  8686.         volatilep = constp = 0;
  8687.       }
  8688.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  8689.       type = build_pointer_type (type);
  8690.     else if (TREE_CODE (type) == OFFSET_TYPE)
  8691.       type = build_pointer_type (type);
  8692.  
  8693.     decl = build_decl (PARM_DECL, declarator, type);
  8694.  
  8695.     bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
  8696.             inlinep, friendp, raises != NULL_TREE);
  8697.     if (current_class_type
  8698.         && IS_SIGNATURE (current_class_type))
  8699.       {
  8700.         if (inlinep)
  8701.           error ("parameter of signature member function declared `inline'");
  8702.         if (RIDBIT_SETP (RID_AUTO, specbits))
  8703.           error ("parameter of signature member function declared `auto'");
  8704.         if (RIDBIT_SETP (RID_REGISTER, specbits))
  8705.           error ("parameter of signature member function declared `register'");
  8706.       }
  8707.  
  8708.     /* Compute the type actually passed in the parmlist,
  8709.        for the case where there is no prototype.
  8710.        (For example, shorts and chars are passed as ints.)
  8711.        When there is a prototype, this is overridden later.  */
  8712.  
  8713.     DECL_ARG_TYPE (decl) = type_promotes_to (type);
  8714.       }
  8715.     else if (decl_context == FIELD)
  8716.       {
  8717.     if (type == error_mark_node)
  8718.       {
  8719.         /* Happens when declaring arrays of sizes which
  8720.            are error_mark_node, for example.  */
  8721.         decl = NULL_TREE;
  8722.       }
  8723.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  8724.       {
  8725.         int publicp = 0;
  8726.  
  8727.         if (friendp == 0)
  8728.           {
  8729.         if (ctype == NULL_TREE)
  8730.           ctype = current_class_type;
  8731.  
  8732.         if (ctype == NULL_TREE)
  8733.           {
  8734.             cp_error ("can't make `%D' into a method -- not in a class",
  8735.                   declarator);
  8736.             return void_type_node;
  8737.           }
  8738.  
  8739.         /* ``A union may [ ... ] not [ have ] virtual functions.''
  8740.            ARM 9.5 */
  8741.         if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
  8742.           {
  8743.             cp_error ("function `%D' declared virtual inside a union",
  8744.                   declarator);
  8745.             return void_type_node;
  8746.           }
  8747.  
  8748.         if (declarator == ansi_opname[(int) NEW_EXPR]
  8749.             || declarator == ansi_opname[(int) VEC_NEW_EXPR]
  8750.             || declarator == ansi_opname[(int) DELETE_EXPR]
  8751.             || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
  8752.           {
  8753.             if (virtualp)
  8754.               {
  8755.             cp_error ("`%D' cannot be declared virtual, since it is always static",
  8756.                   declarator);
  8757.             virtualp = 0;
  8758.               }
  8759.           }
  8760.         else if (staticp < 2)
  8761.           type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8762.                           TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8763.           }
  8764.  
  8765.         /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
  8766.         publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
  8767.                || (ctype != NULL_TREE
  8768.                && funcdef_flag >= 0
  8769.                && RIDBIT_NOTSETP (RID_INLINE, specbits))
  8770.                || (friendp
  8771.                && ! funcdef_flag
  8772.                && RIDBIT_NOTSETP (RID_STATIC, specbits)
  8773.                && RIDBIT_NOTSETP (RID_INLINE, specbits)));
  8774.         decl = grokfndecl (ctype, type, declarator,
  8775.                    virtualp, flags, quals,
  8776.                    raises, friendp ? -1 : 0, publicp);
  8777.         if (decl == NULL_TREE)
  8778.           return NULL_TREE;
  8779.  
  8780.         DECL_INLINE (decl) = inlinep;
  8781.       }
  8782.     else if (TREE_CODE (type) == METHOD_TYPE)
  8783.       {
  8784.         /* All method decls are public, so tell grokfndecl to set
  8785.            TREE_PUBLIC, also.  */
  8786.         decl = grokfndecl (ctype, type, declarator,
  8787.                    virtualp, flags, quals,
  8788.                    raises, friendp ? -1 : 0, 1);
  8789.         if (decl == NULL_TREE)
  8790.           return NULL_TREE;
  8791.  
  8792.         DECL_INLINE (decl) = inlinep;
  8793.       }
  8794.     else if (TREE_CODE (type) == RECORD_TYPE
  8795.          && CLASSTYPE_DECLARED_EXCEPTION (type))
  8796.       {
  8797.         /* Handle a class-local exception declaration.  */
  8798.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  8799.         if (ctype == NULL_TREE)
  8800.           ctype = current_class_type;
  8801.         return void_type_node;
  8802.       }
  8803.     else if (TYPE_SIZE (type) == NULL_TREE && !staticp
  8804.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  8805.       {
  8806.         error ("field `%s' has incomplete type",
  8807.            IDENTIFIER_POINTER (declarator));
  8808.  
  8809.         /* If we're instantiating a template, tell them which
  8810.            instantiation made the field's type be incomplete.  */
  8811.         if (current_class_type
  8812.         && TYPE_NAME (current_class_type)
  8813.         && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
  8814.         && declspecs && TREE_VALUE (declspecs)
  8815.         && TREE_TYPE (TREE_VALUE (declspecs)) == type)
  8816.           error ("  in instantiation of template `%s'",
  8817.              TYPE_NAME_STRING (current_class_type));
  8818.         
  8819.         type = error_mark_node;
  8820.         decl = NULL_TREE;
  8821.       }
  8822.     else
  8823.       {
  8824.         if (friendp)
  8825.           {
  8826.         error ("`%s' is neither function nor method; cannot be declared friend",
  8827.                IDENTIFIER_POINTER (declarator));
  8828.         friendp = 0;
  8829.           }
  8830.         decl = NULL_TREE;
  8831.       }
  8832.  
  8833.     if (friendp)
  8834.       {
  8835.         /* Friends are treated specially.  */
  8836.         if (ctype == current_class_type)
  8837.           warning ("member functions are implicitly friends of their class");
  8838.         else
  8839.           {
  8840.         tree t = NULL_TREE;
  8841.         if (decl && DECL_NAME (decl))
  8842.           t = do_friend (ctype, declarator, decl,
  8843.                  last_function_parms, flags, quals);
  8844.         if (t && funcdef_flag)
  8845.           return t;
  8846.         
  8847.         return void_type_node;
  8848.           }
  8849.       }
  8850.  
  8851.     /* Structure field.  It may not be a function, except for C++ */
  8852.  
  8853.     if (decl == NULL_TREE)
  8854.       {
  8855.         if (initialized)
  8856.           {
  8857.         /* Motion 10 at San Diego: If a static const integral data
  8858.            member is initialized with an integral constant
  8859.            expression, the initializer may appear either in the
  8860.            declaration (within the class), or in the definition,
  8861.            but not both.  If it appears in the class, the member is
  8862.            a member constant.  The file-scope definition is always
  8863.            required.  */
  8864.         if (staticp)
  8865.           {
  8866.             if (pedantic)
  8867.               {
  8868.             if (! constp)
  8869.               cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  8870.                       declarator);
  8871.  
  8872.             else if (! INTEGRAL_TYPE_P (type))
  8873.               cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
  8874.               }
  8875.           }
  8876.  
  8877.         /* Note that initialization of const members is prohibited
  8878.            by the draft ANSI standard, though it appears to be in
  8879.            common practice.  12.6.2: The argument list is used to
  8880.            initialize the named nonstatic member....  This (or an
  8881.            initializer list) is the only way to initialize
  8882.            nonstatic const and reference members.  */
  8883.         else if (flag_ansi || ! constp)
  8884.           cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
  8885.                   constp ? "const member" : "member", declarator);
  8886.           }
  8887.  
  8888.         if (staticp || (constp && initialized))
  8889.           {
  8890.         /* C++ allows static class members.
  8891.            All other work for this is done by grokfield.
  8892.            This VAR_DECL is built by build_lang_field_decl.
  8893.            All other VAR_DECLs are built by build_decl.  */
  8894.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  8895.         TREE_STATIC (decl) = 1;
  8896.         /* In class context, 'static' means public access.  */
  8897.         TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
  8898.           }
  8899.         else
  8900.           {
  8901.         decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  8902.         if (RIDBIT_SETP (RID_MUTABLE, specbits))
  8903.           {
  8904.             DECL_MUTABLE_P (decl) = 1;
  8905.             RIDBIT_RESET (RID_MUTABLE, specbits);
  8906.           }
  8907.           }
  8908.  
  8909.         bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
  8910.                 inlinep, friendp, raises != NULL_TREE);
  8911.       }
  8912.       }
  8913.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  8914.       {
  8915.     tree original_name = declarator;
  8916.     int publicp = 0;
  8917.  
  8918.     if (! declarator)
  8919.       return NULL_TREE;
  8920.  
  8921.     if (RIDBIT_SETP (RID_AUTO, specbits))
  8922.       error ("storage class `auto' invalid for function `%s'", name);
  8923.     else if (RIDBIT_SETP (RID_REGISTER, specbits))
  8924.       error ("storage class `register' invalid for function `%s'", name);
  8925.  
  8926.     /* Function declaration not at top level.
  8927.        Storage classes other than `extern' are not allowed
  8928.        and `extern' makes no difference.  */
  8929.     if (current_binding_level != global_binding_level
  8930.         && ! processing_template_decl
  8931.         && (RIDBIT_SETP (RID_STATIC, specbits)
  8932.         || RIDBIT_SETP (RID_INLINE, specbits))
  8933.         && pedantic)
  8934.       {
  8935.         if (RIDBIT_SETP (RID_STATIC, specbits))
  8936.           pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
  8937.         else
  8938.           pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
  8939.       }
  8940.     
  8941.     if (ctype == NULL_TREE)
  8942.       {
  8943.         if (virtualp)
  8944.           {
  8945.         error ("virtual non-class function `%s'", name);
  8946.         virtualp = 0;
  8947.           }
  8948.  
  8949.         if (current_lang_name == lang_name_cplusplus
  8950.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  8951.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  8952.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  8953.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  8954.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  8955.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  8956.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  8957.           /* Plain overloading: will not be grok'd by grokclassfn.  */
  8958.           declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
  8959.       }
  8960.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  8961.       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8962.                       TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8963.  
  8964.     /* Record presence of `static'.  In C++, `inline' is like `static'.
  8965.        Methods of classes should be public, unless we're dropping them
  8966.        into some other file, so we don't clear TREE_PUBLIC for them.  */
  8967.     publicp
  8968.       = ((ctype
  8969.           && CLASSTYPE_INTERFACE_KNOWN (ctype))
  8970.          || !(RIDBIT_SETP (RID_STATIC, specbits)
  8971.           || RIDBIT_SETP (RID_INLINE, specbits)));
  8972.  
  8973.     decl = grokfndecl (ctype, type, original_name,
  8974.                virtualp, flags, quals,
  8975.                raises,
  8976.                processing_template_decl ? 0 : friendp ? 2 : 1,
  8977.                publicp);
  8978.     if (decl == NULL_TREE)
  8979.       return NULL_TREE;
  8980.  
  8981.     if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
  8982.       DECL_ASSEMBLER_NAME (decl) = declarator;
  8983.  
  8984.     if (staticp == 1)
  8985.       {
  8986.         int illegal_static = 0;
  8987.  
  8988.         /* Don't allow a static member function in a class, and forbid
  8989.            declaring main to be static.  */
  8990.         if (TREE_CODE (type) == METHOD_TYPE)
  8991.           {
  8992.         cp_error_at ("cannot declare member function `%D' to have static linkage", decl);
  8993.         illegal_static = 1;
  8994.           }
  8995.         else if (! ctype
  8996.              && IDENTIFIER_LENGTH (original_name) == 4
  8997.              && IDENTIFIER_POINTER (original_name)[0] == 'm'
  8998.              && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  8999.           {
  9000.         error ("cannot declare function `main' to have static linkage");
  9001.         illegal_static = 1;
  9002.           }
  9003.         else if (current_function_decl)
  9004.           {
  9005.         /* FIXME need arm citation */
  9006.         error ("cannot declare static function inside another function");
  9007.         illegal_static = 1;
  9008.           }
  9009.  
  9010.         if (illegal_static)
  9011.           {
  9012.         staticp = 0;
  9013.         RIDBIT_RESET (RID_STATIC, specbits);
  9014.           }
  9015.       }
  9016.  
  9017.     /* Record presence of `inline', if it is reasonable.  */
  9018.     if (inlinep)
  9019.       {
  9020.         tree last = tree_last (TYPE_ARG_TYPES (type));
  9021.  
  9022.         if (! ctype
  9023.         && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  9024.           error ("cannot inline function `main'");
  9025.         else if (last && last != void_list_node)
  9026.           cp_warning ("cannot inline function `%D' which takes `...'", original_name);
  9027.         else
  9028.           /* Assume that otherwise the function can be inlined.  */
  9029.           DECL_INLINE (decl) = 1;
  9030.  
  9031.         if (RIDBIT_SETP (RID_EXTERN, specbits))
  9032.           {
  9033.         current_extern_inline = 1;
  9034.         if (flag_ansi)
  9035.           pedwarn ("ANSI C++ does not permit `extern inline'");
  9036.           }
  9037.       }
  9038.       }
  9039.     else
  9040.       {
  9041.     /* It's a variable.  */
  9042.  
  9043.     /* An uninitialized decl with `extern' is a reference.  */
  9044.     decl = grokvardecl (type, declarator, specbits, initialized);
  9045.     bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
  9046.             inlinep, friendp, raises != NULL_TREE);
  9047.  
  9048.     if (ctype)
  9049.       {
  9050.         DECL_CONTEXT (decl) = ctype;
  9051.         if (staticp == 1)
  9052.           {
  9053.             cp_error ("static member `%D' re-declared as static",
  9054.               decl);
  9055.             staticp = 0;
  9056.         RIDBIT_RESET (RID_STATIC, specbits);
  9057.           }
  9058.         if (RIDBIT_SETP (RID_EXTERN, specbits))
  9059.           {
  9060.             cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
  9061.               decl);
  9062.         RIDBIT_RESET (RID_EXTERN, specbits);
  9063.           }
  9064.       }
  9065.       }
  9066.  
  9067.     if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9068.       {
  9069.     error ("`%s' cannot be declared mutable", name);
  9070.       }
  9071.  
  9072.     /* Record `register' declaration for warnings on &
  9073.        and in case doing stupid register allocation.  */
  9074.  
  9075.     if (RIDBIT_SETP (RID_REGISTER, specbits))
  9076.       DECL_REGISTER (decl) = 1;
  9077.  
  9078.     if (RIDBIT_SETP (RID_EXTERN, specbits))
  9079.       DECL_THIS_EXTERN (decl) = 1;
  9080.  
  9081.     /* Record constancy and volatility.  */
  9082.  
  9083.     if (constp)
  9084.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  9085.     if (volatilep)
  9086.       {
  9087.     TREE_SIDE_EFFECTS (decl) = 1;
  9088.     TREE_THIS_VOLATILE (decl) = 1;
  9089.       }
  9090.  
  9091.     return decl;
  9092.   }
  9093. }
  9094.  
  9095. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  9096.    An empty exprlist is a parmlist.  An exprlist which
  9097.    contains only identifiers at the global level
  9098.    is a parmlist.  Otherwise, it is an exprlist.  */
  9099. int
  9100. parmlist_is_exprlist (exprs)
  9101.      tree exprs;
  9102. {
  9103.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  9104.     return 0;
  9105.  
  9106.   if (current_binding_level == global_binding_level)
  9107.     {
  9108.       /* At the global level, if these are all identifiers,
  9109.      then it is a parmlist.  */
  9110.       while (exprs)
  9111.     {
  9112.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  9113.         return 1;
  9114.       exprs = TREE_CHAIN (exprs);
  9115.     }
  9116.       return 0;
  9117.     }
  9118.   return 1;
  9119. }
  9120.  
  9121. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  9122.    be complete.
  9123.  
  9124.    C++: also subroutine of `start_function'.  */
  9125. static void
  9126. require_complete_types_for_parms (parms)
  9127.      tree parms;
  9128. {
  9129.   while (parms)
  9130.     {
  9131.       tree type = TREE_TYPE (parms);
  9132.       if (TYPE_SIZE (type) == NULL_TREE)
  9133.     {
  9134.       if (DECL_NAME (parms))
  9135.         error ("parameter `%s' has incomplete type",
  9136.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  9137.       else
  9138.         error ("parameter has incomplete type");
  9139.       TREE_TYPE (parms) = error_mark_node;
  9140.     }
  9141. #if 0
  9142.       /* If the arg types are incomplete in a declaration,
  9143.      they must include undefined tags.
  9144.      These tags can never be defined in the scope of the declaration,
  9145.      so the types can never be completed,
  9146.      and no call can be compiled successfully.  */
  9147.       /* This is not the right behavior for C++, but not having
  9148.      it is also probably wrong.  */
  9149.       else
  9150.     {
  9151.       /* Now warn if is a pointer to an incomplete type.  */
  9152.       while (TREE_CODE (type) == POINTER_TYPE
  9153.          || TREE_CODE (type) == REFERENCE_TYPE)
  9154.         type = TREE_TYPE (type);
  9155.       type = TYPE_MAIN_VARIANT (type);
  9156.       if (TYPE_SIZE (type) == NULL_TREE)
  9157.         {
  9158.           if (DECL_NAME (parm) != NULL_TREE)
  9159.         warning ("parameter `%s' points to incomplete type",
  9160.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  9161.           else
  9162.         warning ("parameter points to incomplete type");
  9163.         }
  9164.     }
  9165. #endif
  9166.       parms = TREE_CHAIN (parms);
  9167.     }
  9168. }
  9169.  
  9170. /* Decode the list of parameter types for a function type.
  9171.    Given the list of things declared inside the parens,
  9172.    return a list of types.
  9173.  
  9174.    The list we receive can have three kinds of elements:
  9175.    an IDENTIFIER_NODE for names given without types,
  9176.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  9177.    or void_type_node, to mark the end of an argument list
  9178.    when additional arguments are not permitted (... was not used).
  9179.  
  9180.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  9181.    a mere declaration.  A nonempty identifier-list gets an error message
  9182.    when FUNCDEF_FLAG is zero.
  9183.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  9184.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  9185.  
  9186.    If all elements of the input list contain types,
  9187.    we return a list of the types.
  9188.    If all elements contain no type (except perhaps a void_type_node
  9189.    at the end), we return a null list.
  9190.    If some have types and some do not, it is an error, and we
  9191.    return a null list.
  9192.  
  9193.    Also set last_function_parms to either
  9194.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  9195.    A list of names is converted to a chain of PARM_DECLs
  9196.    by store_parm_decls so that ultimately it is always a chain of decls.
  9197.  
  9198.    Note that in C++, parameters can take default values.  These default
  9199.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  9200.    an error to specify default values which are followed by parameters
  9201.    that have no default values, or an ELLIPSES.  For simplicities sake,
  9202.    only parameters which are specified with their types can take on
  9203.    default values.  */
  9204.  
  9205. static tree
  9206. grokparms (first_parm, funcdef_flag)
  9207.      tree first_parm;
  9208.      int funcdef_flag;
  9209. {
  9210.   tree result = NULL_TREE;
  9211.   tree decls = NULL_TREE;
  9212.  
  9213.   if (first_parm != NULL_TREE
  9214.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  9215.     {
  9216.       if (! funcdef_flag)
  9217.     pedwarn ("parameter names (without types) in function declaration");
  9218.       last_function_parms = first_parm;
  9219.       return NULL_TREE;
  9220.     }
  9221.   else if (first_parm != NULL_TREE
  9222.        && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
  9223.        && TREE_VALUE (first_parm) != void_type_node)
  9224.     my_friendly_abort (145);
  9225.   else
  9226.     {
  9227.       /* Types were specified.  This is a list of declarators
  9228.      each represented as a TREE_LIST node.  */
  9229.       register tree parm, chain;
  9230.       int any_init = 0, any_error = 0, saw_void = 0;
  9231.  
  9232.       if (first_parm != NULL_TREE)
  9233.     {
  9234.       tree last_result = NULL_TREE;
  9235.       tree last_decl = NULL_TREE;
  9236.  
  9237.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  9238.         {
  9239.           tree type, list_node = parm;
  9240.           register tree decl = TREE_VALUE (parm);
  9241.           tree init = TREE_PURPOSE (parm);
  9242.  
  9243.           chain = TREE_CHAIN (parm);
  9244.           /* @@ weak defense against parse errors.  */
  9245.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  9246.         {
  9247.           /* Give various messages as the need arises.  */
  9248.           if (TREE_CODE (decl) == STRING_CST)
  9249.             error ("invalid string constant `%s'",
  9250.                TREE_STRING_POINTER (decl));
  9251.           else if (TREE_CODE (decl) == INTEGER_CST)
  9252.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  9253.           continue;
  9254.         }
  9255.  
  9256.           if (decl != void_type_node)
  9257.         {
  9258.           /* @@ May need to fetch out a `raises' here.  */
  9259.           decl = grokdeclarator (TREE_VALUE (decl),
  9260.                      TREE_PURPOSE (decl),
  9261.                      PARM, init != NULL_TREE, NULL_TREE);
  9262.           if (! decl)
  9263.             continue;
  9264.           type = TREE_TYPE (decl);
  9265.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  9266.             decl = void_type_node;
  9267.           else if (TREE_CODE (type) == METHOD_TYPE)
  9268.             {
  9269.               if (DECL_NAME (decl))
  9270.             /* Cannot use `error_with_decl' here because
  9271.                we don't have DECL_CONTEXT set up yet.  */
  9272.             error ("parameter `%s' invalidly declared method type",
  9273.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  9274.               else
  9275.             error ("parameter invalidly declared method type");
  9276.               type = build_pointer_type (type);
  9277.               TREE_TYPE (decl) = type;
  9278.             }
  9279.           else if (TREE_CODE (type) == OFFSET_TYPE)
  9280.             {
  9281.               if (DECL_NAME (decl))
  9282.             error ("parameter `%s' invalidly declared offset type",
  9283.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  9284.               else
  9285.             error ("parameter invalidly declared offset type");
  9286.               type = build_pointer_type (type);
  9287.               TREE_TYPE (decl) = type;
  9288.             }
  9289.                   else if (TREE_CODE (type) == RECORD_TYPE
  9290.                            && TYPE_LANG_SPECIFIC (type)
  9291.                            && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  9292.                     {
  9293.                       abstract_virtuals_error (decl, type);
  9294.                       any_error = 1;  /* seems like a good idea */
  9295.                     }
  9296.                   else if (TREE_CODE (type) == RECORD_TYPE
  9297.                            && TYPE_LANG_SPECIFIC (type)
  9298.                            && IS_SIGNATURE (type))
  9299.                     {
  9300.                       signature_error (decl, type);
  9301.                       any_error = 1;  /* seems like a good idea */
  9302.                     }
  9303.         }
  9304.  
  9305.           if (decl == void_type_node)
  9306.         {
  9307.           if (result == NULL_TREE)
  9308.             {
  9309.               result = void_list_node;
  9310.               last_result = result;
  9311.             }
  9312.           else
  9313.             {
  9314.               TREE_CHAIN (last_result) = void_list_node;
  9315.               last_result = void_list_node;
  9316.             }
  9317.           saw_void = 1;
  9318.           if (chain
  9319.               && (chain != void_list_node || TREE_CHAIN (chain)))
  9320.             error ("`void' in parameter list must be entire list");
  9321.           break;
  9322.         }
  9323.  
  9324.           /* Since there is a prototype, args are passed in their own types.  */
  9325.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  9326. #ifdef PROMOTE_PROTOTYPES
  9327.           if ((TREE_CODE (type) == INTEGER_TYPE
  9328.            || TREE_CODE (type) == ENUMERAL_TYPE)
  9329.           && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  9330.         DECL_ARG_TYPE (decl) = integer_type_node;
  9331. #endif
  9332.           if (!any_error)
  9333.         {
  9334.           if (init)
  9335.             {
  9336.               any_init++;
  9337.               if (TREE_CODE (init) == SAVE_EXPR)
  9338.             PARM_DECL_EXPR (init) = 1;
  9339.               else if (TREE_CODE (init) == VAR_DECL)
  9340.             {
  9341.               if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
  9342.                 {
  9343.                   /* ``Local variables may not be used in default
  9344.                  argument expressions.'' dpANSI C++ 8.2.6 */
  9345.                   /* If extern int i; within a function is not
  9346.                  considered a local variable, then this code is
  9347.                  wrong. */
  9348.                   cp_error ("local variable `%D' may not be used as a default argument", init);
  9349.                   any_error = 1;
  9350.                 }
  9351.               else if (TREE_READONLY_DECL_P (init))
  9352.                 init = decl_constant_value (init);
  9353.             }
  9354.               else
  9355.             init = require_instantiated_type (type, init, integer_zero_node);
  9356.             }
  9357.           else if (any_init)
  9358.             {
  9359.               error ("all trailing parameters must have default arguments");
  9360.               any_error = 1;
  9361.             }
  9362.         }
  9363.           else
  9364.         init = NULL_TREE;
  9365.  
  9366.           if (decls == NULL_TREE)
  9367.         {
  9368.           decls = decl;
  9369.           last_decl = decls;
  9370.         }
  9371.           else
  9372.         {
  9373.           TREE_CHAIN (last_decl) = decl;
  9374.           last_decl = decl;
  9375.         }
  9376.           if (TREE_PERMANENT (list_node))
  9377.         {
  9378.           TREE_PURPOSE (list_node) = init;
  9379.           TREE_VALUE (list_node) = type;
  9380.           TREE_CHAIN (list_node) = NULL_TREE;
  9381.         }
  9382.           else
  9383.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  9384.           if (result == NULL_TREE)
  9385.         {
  9386.           result = list_node;
  9387.           last_result = result;
  9388.         }
  9389.           else
  9390.         {
  9391.           TREE_CHAIN (last_result) = list_node;
  9392.           last_result = list_node;
  9393.         }
  9394.         }
  9395.       if (last_result)
  9396.         TREE_CHAIN (last_result) = NULL_TREE;
  9397.       /* If there are no parameters, and the function does not end
  9398.          with `...', then last_decl will be NULL_TREE.  */
  9399.       if (last_decl != NULL_TREE)
  9400.         TREE_CHAIN (last_decl) = NULL_TREE;
  9401.     }
  9402.     }
  9403.  
  9404.   last_function_parms = decls;
  9405.  
  9406.   /* In a fcn definition, arg types must be complete.  */
  9407.   if (funcdef_flag > 0)
  9408.     require_complete_types_for_parms (last_function_parms);
  9409.  
  9410.   return result;
  9411. }
  9412.  
  9413. /* These memoizing functions keep track of special properties which
  9414.    a class may have.  `grok_ctor_properties' notices whether a class
  9415.    has a constructor of the form X(X&), and also complains
  9416.    if the class has a constructor of the form X(X).
  9417.    `grok_op_properties' takes notice of the various forms of
  9418.    operator= which are defined, as well as what sorts of type conversion
  9419.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  9420. int
  9421. grok_ctor_properties (ctype, decl)
  9422.      tree ctype, decl;
  9423. {
  9424.   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
  9425.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  9426.  
  9427.   /* When a type has virtual baseclasses, a magical first int argument is
  9428.      added to any ctor so we can tell if the class has been initialized
  9429.      yet.  This could screw things up in this function, so we deliberately
  9430.      ignore the leading int if we're in that situation.  */
  9431.   if (parmtypes
  9432.       && TREE_VALUE (parmtypes) == integer_type_node
  9433.       && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
  9434.     {
  9435.       parmtypes = TREE_CHAIN (parmtypes);
  9436.       parmtype = TREE_VALUE (parmtypes);
  9437.     }
  9438.  
  9439.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  9440.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  9441.     {
  9442.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  9443.       || TREE_CHAIN (parmtypes) == void_list_node
  9444.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  9445.     {
  9446.       TYPE_HAS_INIT_REF (ctype) = 1;
  9447.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  9448.         TYPE_HAS_CONST_INIT_REF (ctype) = 1;
  9449.     }
  9450.       else
  9451.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  9452.     }
  9453.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  9454.     {
  9455.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  9456.       && TREE_CHAIN (parmtypes) == void_list_node)
  9457.     {
  9458.       cp_error ("invalid constructor; you probably meant `%T (%T&)'",
  9459.             ctype, ctype);
  9460.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  9461.  
  9462.       return 0;
  9463.     }
  9464.       else
  9465.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  9466.     }
  9467.   else if (TREE_CODE (parmtype) == VOID_TYPE
  9468.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  9469.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  9470.  
  9471.   return 1;
  9472. }
  9473.  
  9474. /* An operator with this name can be either unary or binary.  */
  9475. static int
  9476. ambi_op_p (name)
  9477.      tree name;
  9478. {
  9479.   return (name == ansi_opname [(int) INDIRECT_REF]
  9480.       || name == ansi_opname [(int) ADDR_EXPR]
  9481.       || name == ansi_opname [(int) NEGATE_EXPR]
  9482.       || name == ansi_opname[(int) POSTINCREMENT_EXPR]
  9483.       || name == ansi_opname[(int) POSTDECREMENT_EXPR]
  9484.       || name == ansi_opname [(int) CONVERT_EXPR]);
  9485. }
  9486.  
  9487. /* An operator with this name can only be unary.  */
  9488. static int
  9489. unary_op_p (name)
  9490.      tree name;
  9491. {
  9492.   return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
  9493.       || name == ansi_opname [(int) BIT_NOT_EXPR]
  9494.       || name == ansi_opname [(int) COMPONENT_REF]
  9495.       || OPERATOR_TYPENAME_P (name));
  9496. }
  9497.  
  9498. /* Do a little sanity-checking on how they declared their operator.  */
  9499. static void
  9500. grok_op_properties (decl, virtualp, friendp)
  9501.      tree decl;
  9502.      int virtualp, friendp;
  9503. {
  9504.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  9505.   int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
  9506.   tree name = DECL_NAME (decl);
  9507.  
  9508.   if (current_class_type == NULL_TREE)
  9509.     friendp = 1;
  9510.  
  9511.   if (! friendp)
  9512.     {
  9513.       if (name == ansi_opname[(int) MODIFY_EXPR])
  9514.     TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
  9515.       else if (name == ansi_opname[(int) CALL_EXPR])
  9516.     TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
  9517.       else if (name == ansi_opname[(int) ARRAY_REF])
  9518.     TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
  9519.       else if (name == ansi_opname[(int) COMPONENT_REF]
  9520.            || name == ansi_opname[(int) MEMBER_REF])
  9521.     TYPE_OVERLOADS_ARROW (current_class_type) = 1;
  9522.       else if (name == ansi_opname[(int) NEW_EXPR])
  9523.     TYPE_GETS_NEW (current_class_type) |= 1;
  9524.       else if (name == ansi_opname[(int) DELETE_EXPR])
  9525.     TYPE_GETS_DELETE (current_class_type) |= 1;
  9526.       else if (name == ansi_opname[(int) VEC_NEW_EXPR])
  9527.     TYPE_GETS_NEW (current_class_type) |= 2;
  9528.       else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
  9529.     TYPE_GETS_DELETE (current_class_type) |= 2;
  9530.     }
  9531.  
  9532.   if (name == ansi_opname[(int) NEW_EXPR]
  9533.       || name == ansi_opname[(int) VEC_NEW_EXPR])
  9534.     {
  9535.       /* When the compiler encounters the definition of A::operator new, it
  9536.      doesn't look at the class declaration to find out if it's static.  */
  9537.       if (methodp)
  9538.     revert_static_member_fn (&decl, NULL, NULL);
  9539.      
  9540.       /* Take care of function decl if we had syntax errors.  */
  9541.       if (argtypes == NULL_TREE)
  9542.     TREE_TYPE (decl) =
  9543.       build_function_type (ptr_type_node,
  9544.                    hash_tree_chain (integer_type_node,
  9545.                         void_list_node));
  9546.       else
  9547.     TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
  9548.     }
  9549.   else if (name == ansi_opname[(int) DELETE_EXPR]
  9550.        || name == ansi_opname[(int) VEC_DELETE_EXPR])
  9551.     {
  9552.       if (methodp)
  9553.     revert_static_member_fn (&decl, NULL, NULL);
  9554.      
  9555.       if (argtypes == NULL_TREE)
  9556.     TREE_TYPE (decl) =
  9557.       build_function_type (void_type_node,
  9558.                    hash_tree_chain (ptr_type_node,
  9559.                         void_list_node));
  9560.       else
  9561.     {
  9562.       TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
  9563.  
  9564.       if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
  9565.           && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
  9566.           != void_list_node))
  9567.         TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
  9568.     }
  9569.     }
  9570.   else
  9571.     {
  9572.       /* An operator function must either be a non-static member function
  9573.      or have at least one parameter of a class, a reference to a class,
  9574.      an enumeration, or a reference to an enumeration.  13.4.0.6 */
  9575.       if (! methodp || DECL_STATIC_FUNCTION_P (decl))
  9576.     {
  9577.       if (OPERATOR_TYPENAME_P (name)
  9578.           || name == ansi_opname[(int) CALL_EXPR]
  9579.           || name == ansi_opname[(int) MODIFY_EXPR]
  9580.           || name == ansi_opname[(int) COMPONENT_REF]
  9581.           || name == ansi_opname[(int) ARRAY_REF])
  9582.         cp_error ("`%D' must be a nonstatic member function", decl);
  9583.       else
  9584.         {
  9585.           tree p = argtypes;
  9586.  
  9587.           if (DECL_STATIC_FUNCTION_P (decl))
  9588.         cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
  9589.  
  9590.           if (p)
  9591.         for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
  9592.           {
  9593.             tree arg = TREE_VALUE (p);
  9594.             if (TREE_CODE (arg) == REFERENCE_TYPE)
  9595.               arg = TREE_TYPE (arg);
  9596.  
  9597.             /* This lets bad template code slip through.  */
  9598.             if (IS_AGGR_TYPE (arg)
  9599.             || TREE_CODE (arg) == ENUMERAL_TYPE
  9600.             || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
  9601.               goto foundaggr;
  9602.           }
  9603.           cp_error
  9604.         ("`%D' must have an argument of class or enumerated type",
  9605.          decl);
  9606.         foundaggr:
  9607.           ;
  9608.         }
  9609.     }
  9610.       
  9611.       if (name == ansi_opname[(int) CALL_EXPR]
  9612.       || name == ansi_opname[(int) METHOD_CALL_EXPR])
  9613.     return;            /* no restrictions on args */
  9614.  
  9615.       if (IDENTIFIER_TYPENAME_P (name))
  9616.     {
  9617.       tree t = TREE_TYPE (name);
  9618.       if (TREE_CODE (t) == VOID_TYPE)
  9619.         pedwarn ("void is not a valid type conversion operator");
  9620.       else if (! friendp)
  9621.         {
  9622.           int ref = (TREE_CODE (t) == REFERENCE_TYPE);
  9623.           char *what = 0;
  9624.           if (ref)
  9625.         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
  9626.  
  9627.           if (t == current_class_type)
  9628.         what = "the same type";
  9629.           else if (IS_AGGR_TYPE (t)
  9630.                && DERIVED_FROM_P (t, current_class_type))
  9631.         what = "a base class";
  9632.  
  9633.           if (what)
  9634.         warning ("conversion to %s%s will never use a type conversion operator",
  9635.              ref ? "a reference to " : "", what);
  9636.         }
  9637.     }
  9638.  
  9639.       if (name == ansi_opname[(int) MODIFY_EXPR])
  9640.     {
  9641.       tree parmtype;
  9642.  
  9643.       if (list_length (argtypes) != 3 && methodp)
  9644.         {
  9645.           cp_error ("`%D' must take exactly one argument", decl);
  9646.           return;
  9647.         }
  9648.       parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
  9649.  
  9650.       if (copy_assignment_arg_p (parmtype, virtualp)
  9651.           && ! friendp)
  9652.         {
  9653.           TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  9654.           if (TREE_CODE (parmtype) != REFERENCE_TYPE
  9655.           || TYPE_READONLY (TREE_TYPE (parmtype)))
  9656.         TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
  9657. #if 0 /* Too soon; done in grok_function_init */
  9658.           if (DECL_ABSTRACT_VIRTUAL_P (decl))
  9659.         TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
  9660. #endif
  9661.         }
  9662.     }
  9663.       else if (name == ansi_opname[(int) COND_EXPR])
  9664.     {
  9665.       /* 13.4.0.3 */
  9666.       pedwarn ("ANSI C++ prohibits overloading operator ?:");
  9667.       if (list_length (argtypes) != 4)
  9668.         cp_error ("`%D' must take exactly three arguments", decl);
  9669.     }      
  9670.       else if (ambi_op_p (name))
  9671.     {
  9672.       if (list_length (argtypes) == 2)
  9673.         /* prefix */;
  9674.       else if (list_length (argtypes) == 3)
  9675.         {
  9676.           if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
  9677.            || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  9678.           && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
  9679.         {
  9680.           if (methodp)
  9681.             cp_error ("postfix `%D' must take `int' as its argument",
  9682.                   decl);
  9683.           else
  9684.             cp_error
  9685.               ("postfix `%D' must take `int' as its second argument",
  9686.                decl);
  9687.         }
  9688.         }
  9689.       else
  9690.         {
  9691.           if (methodp)
  9692.         cp_error ("`%D' must take either zero or one argument", decl);
  9693.           else
  9694.         cp_error ("`%D' must take either one or two arguments", decl);
  9695.         }
  9696.     }
  9697.       else if (unary_op_p (name))
  9698.     {
  9699.       if (list_length (argtypes) != 2)
  9700.         {
  9701.           if (methodp)
  9702.         cp_error ("`%D' must take `void'", decl);
  9703.           else
  9704.         cp_error ("`%D' must take exactly one argument", decl);
  9705.         }
  9706.     }
  9707.       else /* if (binary_op_p (name)) */
  9708.     {
  9709.       if (list_length (argtypes) != 3)
  9710.         {
  9711.           if (methodp)
  9712.         cp_error ("`%D' must take exactly one argument", decl);
  9713.           else
  9714.         cp_error ("`%D' must take exactly two arguments", decl);
  9715.         }
  9716.     }
  9717.  
  9718.       /* 13.4.0.8 */
  9719.       if (argtypes)
  9720.     for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
  9721.       if (TREE_PURPOSE (argtypes))
  9722.         {
  9723.           TREE_PURPOSE (argtypes) = NULL_TREE;
  9724.           if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
  9725.           || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  9726.         {
  9727.           if (pedantic)
  9728.             cp_pedwarn ("`%D' cannot have default arguments", decl);
  9729.         }
  9730.           else
  9731.         cp_error ("`%D' cannot have default arguments", decl);
  9732.         }
  9733.     }
  9734. }
  9735.  
  9736. /* Get the struct, enum or union (CODE says which) with tag NAME.
  9737.    Define the tag as a forward-reference if it is not defined.
  9738.  
  9739.    C++: If a class derivation is given, process it here, and report
  9740.    an error if multiple derivation declarations are not identical.
  9741.  
  9742.    If this is a definition, come in through xref_tag and only look in
  9743.    the current frame for the name (since C++ allows new names in any
  9744.    scope.)  */
  9745.  
  9746. /* avoid rewriting all callers of xref_tag */
  9747. static int xref_next_defn = 0;
  9748.  
  9749. tree
  9750. xref_defn_tag (code_type_node, name, binfo)
  9751.      tree code_type_node;
  9752.      tree name, binfo;
  9753. {
  9754.   tree rv, ncp;
  9755.   xref_next_defn = 1;
  9756.  
  9757.   if (class_binding_level)
  9758.     {
  9759.       tree n1;
  9760.       char *buf;
  9761.       /* we need to build a new IDENTIFIER_NODE for name which nukes
  9762.        * the pieces... */
  9763. /*
  9764.       n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
  9765.       if (n1)
  9766.     n1 = DECL_NAME (n1);
  9767.       else
  9768.     n1 = current_class_name;
  9769. */
  9770.       n1 = TYPE_NAME (current_class_type);
  9771.       if (n1)
  9772.     n1 = DECL_NESTED_TYPENAME(n1);
  9773.       else
  9774.     n1 = current_class_name;
  9775.       
  9776.       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
  9777.                  + IDENTIFIER_LENGTH (name));
  9778.       
  9779.       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
  9780.            IDENTIFIER_POINTER (name));
  9781.       ncp = get_identifier (buf);
  9782. #ifdef SPEW_DEBUG
  9783.       if (spew_debug)
  9784.     printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
  9785. #endif
  9786. #if 0
  9787.       IDENTIFIER_LOCAL_VALUE (name) =
  9788.     build_decl (TYPE_DECL, ncp, NULL_TREE);
  9789. #endif
  9790.       rv = xref_tag (code_type_node, name, binfo, 0);
  9791.       if (! ANON_AGGRNAME_P (name))
  9792.       {
  9793.     register tree type_decl = build_decl (TYPE_DECL, ncp, rv);
  9794. #ifdef DWARF_DEBUGGING_INFO
  9795.     /* Mark the TYPE_DECL node created just above as a gratuitous one
  9796.        so that dwarfout.c will know not to generate a TAG_typedef DIE
  9797.        for it.  */
  9798.     if (write_symbols == DWARF_DEBUG)
  9799.       DECL_IGNORED_P (type_decl) = 1;
  9800. #endif /* DWARF_DEBUGGING_INFO */
  9801.     pushdecl_nonclass_level (type_decl);
  9802.       }
  9803.     }
  9804.   else
  9805.     {
  9806.       rv = xref_tag (code_type_node, name, binfo, 0);
  9807.     }
  9808.   xref_next_defn = 0;
  9809.   return rv;
  9810. }
  9811.  
  9812. tree
  9813. xref_tag (code_type_node, name, binfo, globalize)
  9814.      tree code_type_node;
  9815.      tree name, binfo;
  9816.      int globalize;
  9817. {
  9818.   enum tag_types tag_code;
  9819.   enum tree_code code;
  9820.   int temp = 0;
  9821.   int i, len;
  9822.   register tree ref, t;
  9823.   struct binding_level *b = inner_binding_level;
  9824.  
  9825.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  9826.   switch (tag_code)
  9827.     {
  9828.     case record_type:
  9829.     case class_type:
  9830.     case exception_type:
  9831.     case signature_type:
  9832.       code = RECORD_TYPE;
  9833.       len = list_length (binfo);
  9834.       break;
  9835.     case union_type:
  9836.       code = UNION_TYPE;
  9837.       if (binfo)
  9838.     {
  9839.       cp_error ("derived union `%T' invalid", name);
  9840.       binfo = NULL_TREE;
  9841.     }
  9842.       len = 0;
  9843.       break;
  9844.     case enum_type:
  9845.       code = ENUMERAL_TYPE;
  9846.       break;
  9847.     default:
  9848.       my_friendly_abort (18);
  9849.     }
  9850.  
  9851.   /* If a cross reference is requested, look up the type
  9852.      already defined for this tag and return it.  */
  9853.   t = IDENTIFIER_TYPE_VALUE (name);
  9854.   if (t && TREE_CODE (t) != code)
  9855.     t = NULL_TREE;
  9856.  
  9857.   if (xref_next_defn)
  9858.     {
  9859.       /* If we know we are defining this tag, only look it up in this scope
  9860.        * and don't try to find it as a type. */
  9861.       xref_next_defn = 0;
  9862.       if (t && TYPE_CONTEXT(t))
  9863.     {
  9864.       if (TREE_MANGLED (name))
  9865.         ref = t;
  9866.       else
  9867.               ref = lookup_tag (code, name, b, 1);
  9868.     }
  9869.       else
  9870.           ref = lookup_tag (code, name, b, 1);
  9871.     }
  9872.   else
  9873.     {
  9874.       if (t)
  9875.     ref = t;
  9876.       else
  9877.         ref = lookup_tag (code, name, b, 0);
  9878.  
  9879.       if (! ref)
  9880.     {
  9881.       /* Try finding it as a type declaration.  If that wins, use it.  */
  9882.       ref = lookup_name (name, 1);
  9883.       if (ref && TREE_CODE (ref) == TYPE_DECL
  9884.           && TREE_CODE (TREE_TYPE (ref)) == code)
  9885.         ref = TREE_TYPE (ref);
  9886.       else
  9887.         ref = NULL_TREE;
  9888.     }
  9889.     }
  9890.  
  9891.   push_obstacks_nochange ();
  9892.  
  9893.   if (! ref)
  9894.     {
  9895.       /* If no such tag is yet defined, create a forward-reference node
  9896.      and record it as the "definition".
  9897.      When a real declaration of this type is found,
  9898.      the forward-reference will be altered into a real type.  */
  9899.  
  9900.       /* In C++, since these migrate into the global scope, we must
  9901.      build them on the permanent obstack.  */
  9902.  
  9903.       temp = allocation_temporary_p ();
  9904.       if (temp)
  9905.     end_temporary_allocation ();
  9906.  
  9907.       if (code == ENUMERAL_TYPE)
  9908.     {
  9909.       ref = make_node (ENUMERAL_TYPE);
  9910.  
  9911.       /* Give the type a default layout like unsigned int
  9912.          to avoid crashing if it does not get defined.  */
  9913.       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
  9914.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  9915.       TREE_UNSIGNED (ref) = 1;
  9916.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  9917.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  9918.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  9919.  
  9920.       /* Enable us to recognize when a type is created in class context.
  9921.          To do nested classes correctly, this should probably be cleared
  9922.          out when we leave this classes scope.  Currently this in only
  9923.          done in `start_enum'.  */
  9924.  
  9925.       pushtag (name, ref, globalize);
  9926.       if (flag_cadillac)
  9927.         cadillac_start_enum (ref);
  9928.     }
  9929.       else if (tag_code == exception_type)
  9930.     {
  9931.       ref = make_lang_type (code);
  9932.       /* Enable us to recognize when an exception type is created in
  9933.          class context.  To do nested classes correctly, this should
  9934.          probably be cleared out when we leave this class's scope.  */
  9935.       CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
  9936.       pushtag (name, ref, globalize);
  9937.       if (flag_cadillac)
  9938.         cadillac_start_struct (ref);
  9939.     }
  9940.       else
  9941.     {
  9942.       extern tree pending_vtables;
  9943.       struct binding_level *old_b = class_binding_level;
  9944.       int needs_writing;
  9945.  
  9946.       ref = make_lang_type (code);
  9947.  
  9948.       /* A signature type will contain the fields of the signature
  9949.          table.  Therefore, it's not only an interface.  */
  9950.       if (tag_code == signature_type)
  9951.         {
  9952.           SET_SIGNATURE (ref);
  9953.           CLASSTYPE_INTERFACE_ONLY (ref) = 0;
  9954.           CLASSTYPE_INTERFACE_UNKNOWN (ref) = 0;
  9955.         }
  9956.  
  9957.       /* Record how to set the access of this class's
  9958.          virtual functions.  If write_virtuals == 2 or 3, then
  9959.          inline virtuals are ``extern inline''.  */
  9960.       switch (write_virtuals)
  9961.         {
  9962.         case 0:
  9963.         case 1:
  9964.           needs_writing = 1;
  9965.           break;
  9966.         case 2:
  9967.           needs_writing = !! value_member (name, pending_vtables);
  9968.           break;
  9969.         case 3:
  9970.           needs_writing = ! CLASSTYPE_INTERFACE_ONLY (ref)
  9971.         && CLASSTYPE_INTERFACE_KNOWN (ref);
  9972.           break;
  9973.         default:
  9974.           needs_writing = 0;
  9975.         }
  9976.  
  9977.       /* Signatures don't have a vtable.  As long as we don't have default
  9978.          implementations, they behave as if `write_virtuals' were 3.  */
  9979.       if (tag_code == signature_type)
  9980.         CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
  9981.       else
  9982.         CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
  9983.  
  9984. #ifdef NONNESTED_CLASSES
  9985.       /* Class types don't nest the way enums do.  */
  9986.       class_binding_level = (struct binding_level *)0;
  9987. #endif
  9988.       pushtag (name, ref, globalize);
  9989.       class_binding_level = old_b;
  9990.  
  9991.       if (flag_cadillac)
  9992.         cadillac_start_struct (ref);
  9993.     }
  9994.     }
  9995.   else
  9996.     {
  9997.       if (IS_AGGR_TYPE_CODE (code))
  9998.     {
  9999.       if (IS_AGGR_TYPE (ref)
  10000.           && ((tag_code == exception_type)
  10001.           != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
  10002.         {
  10003.           cp_error ("type `%T' is both exception and aggregate type", ref);
  10004.           CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
  10005.         }
  10006.     }
  10007.  
  10008.       /* If it no longer looks like a nested type, make sure it's
  10009.      in global scope.  */
  10010.       if (b == global_binding_level && !class_binding_level
  10011.       && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
  10012.     IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
  10013.  
  10014.       if (binfo)
  10015.     {
  10016.       tree tt1 = binfo;
  10017.       tree tt2 = TYPE_BINFO_BASETYPES (ref);
  10018.  
  10019.       if (TYPE_BINFO_BASETYPES (ref))
  10020.         for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
  10021.           if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
  10022.         {
  10023.           cp_error ("redeclaration of derivation chain of type `%#T'",
  10024.                 ref);
  10025.           break;
  10026.         }
  10027.  
  10028.       if (tt1 == NULL_TREE)
  10029.         /* The user told us something we already knew.  */
  10030.         goto just_return;
  10031.  
  10032.       /* In C++, since these migrate into the global scope, we must
  10033.          build them on the permanent obstack.  */
  10034.       end_temporary_allocation ();
  10035.     }
  10036.     }
  10037.  
  10038.   if (binfo)
  10039.     {
  10040.       /* In the declaration `A : X, Y, ... Z' we mark all the types
  10041.      (A, X, Y, ..., Z) so we can check for duplicates.  */
  10042.       tree binfos;
  10043.  
  10044.       SET_CLASSTYPE_MARKED (ref);
  10045.       BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
  10046.  
  10047.       for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
  10048.     {
  10049.       /* The base of a derived struct is public by default.  */
  10050.       int via_public
  10051.         = (TREE_PURPOSE (binfo) == (tree)access_public
  10052.            || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10053.            || (tag_code != class_type
  10054.            && (TREE_PURPOSE (binfo) == (tree)access_default
  10055.                || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
  10056.       int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
  10057.       int via_virtual
  10058.         = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
  10059.            || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10060.            || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
  10061.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  10062.       tree base_binfo;
  10063.  
  10064.       GNU_xref_hier (IDENTIFIER_POINTER (name),
  10065.              IDENTIFIER_POINTER (TREE_VALUE (binfo)),
  10066.              via_public, via_virtual, 0);
  10067.  
  10068.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  10069.         basetype = TREE_TYPE (basetype);
  10070.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  10071.         {
  10072.           error ("base type `%s' fails to be a struct or class type",
  10073.              IDENTIFIER_POINTER (TREE_VALUE (binfo)));
  10074.           continue;
  10075.         }
  10076. #if 1
  10077.       /* This code replaces similar code in layout_basetypes.  */
  10078.       else if (TYPE_SIZE (basetype) == NULL_TREE)
  10079.         {
  10080.           cp_error ("base class `%T' has incomplete type", basetype);
  10081.           continue;
  10082.         }
  10083. #endif
  10084.       else
  10085.         {
  10086.           if (CLASSTYPE_MARKED (basetype))
  10087.         {
  10088.           if (basetype == ref)
  10089.             cp_error ("recursive type `%T' undefined", basetype);
  10090.           else
  10091.             cp_error ("duplicate base type `%T' invalid", basetype);
  10092.           continue;
  10093.         }
  10094.  
  10095.            /* Note that the BINFO records which describe individual
  10096.           inheritances are *not* shared in the lattice!  They
  10097.           cannot be shared because a given baseclass may be
  10098.           inherited with different `accessibility' by different
  10099.           derived classes.  (Each BINFO record describing an
  10100.           individual inheritance contains flags which say what
  10101.           the `accessibility' of that particular inheritance is.)  */
  10102.   
  10103.           base_binfo = make_binfo (integer_zero_node, basetype,
  10104.                   TYPE_BINFO_VTABLE (basetype),
  10105.                    TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
  10106.  
  10107.           TREE_VEC_ELT (binfos, i) = base_binfo;
  10108.           TREE_VIA_PUBLIC (base_binfo) = via_public;
  10109.            TREE_VIA_PROTECTED (base_binfo) = via_protected;
  10110.           TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
  10111.  
  10112.           SET_CLASSTYPE_MARKED (basetype);
  10113. #if 0
  10114. /* XYZZY TEST VIRTUAL BASECLASSES */
  10115. if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
  10116.     && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  10117.     && via_virtual == 0)
  10118.   {
  10119.     warning ("making type `%s' a virtual baseclass",
  10120.          TYPE_NAME_STRING (basetype));
  10121.     via_virtual = 1;
  10122.   }
  10123. #endif
  10124.           /* We are free to modify these bits because they are meaningless
  10125.          at top level, and BASETYPE is a top-level type.  */
  10126.           if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  10127.         {
  10128.           TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  10129.           TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10130.         }
  10131.  
  10132.           TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  10133.           TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
  10134.           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
  10135.           CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  10136.           i += 1;
  10137.         }
  10138.     }
  10139.       if (i)
  10140.     TREE_VEC_LENGTH (binfos) = i;
  10141.       else
  10142.     BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
  10143.  
  10144.       if (i > 1)
  10145.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  10146.       else if (i == 1)
  10147.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  10148.       = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
  10149.       if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
  10150.     TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10151.  
  10152.       /* Unmark all the types.  */
  10153.       while (--i >= 0)
  10154.     CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
  10155.       CLEAR_CLASSTYPE_MARKED (ref);
  10156.     }
  10157.  
  10158.  just_return:
  10159.  
  10160.   /* Until the type is defined, tentatively accept whatever
  10161.      structure tag the user hands us.  */
  10162.   if (TYPE_SIZE (ref) == NULL_TREE
  10163.       && ref != current_class_type
  10164.       /* Have to check this, in case we have contradictory tag info.  */
  10165.       && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
  10166.     {
  10167.       if (tag_code == class_type)
  10168.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  10169.       else if (tag_code == record_type || tag_code == signature_type)
  10170.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  10171.     }
  10172.  
  10173.   pop_obstacks ();
  10174.  
  10175.   return ref;
  10176. }
  10177.  
  10178. static tree current_local_enum = NULL_TREE;
  10179.  
  10180. /* Begin compiling the definition of an enumeration type.
  10181.    NAME is its name (or null if anonymous).
  10182.    Returns the type object, as yet incomplete.
  10183.    Also records info about it so that build_enumerator
  10184.    may be used to declare the individual values as they are read.  */
  10185.  
  10186. tree
  10187. start_enum (name)
  10188.      tree name;
  10189. {
  10190.   register tree enumtype = NULL_TREE;
  10191.   struct binding_level *b = inner_binding_level;
  10192.  
  10193.   /* If this is the real definition for a previous forward reference,
  10194.      fill in the contents in the same object that used to be the
  10195.      forward reference.  */
  10196.  
  10197.   if (name != NULL_TREE)
  10198.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  10199.  
  10200.   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
  10201.     cp_error ("multiple definition of enum `%T'", enumtype);
  10202.   else
  10203.     {
  10204.       enumtype = make_node (ENUMERAL_TYPE);
  10205.       pushtag (name, enumtype, 0);
  10206.     }
  10207.  
  10208.   if (current_class_type)
  10209.     TREE_ADDRESSABLE (b->tags) = 1;
  10210.   current_local_enum = NULL_TREE;
  10211.  
  10212.   if (TYPE_VALUES (enumtype) != NULL_TREE)
  10213.     /* Completely replace its old definition.
  10214.        The old enumerators remain defined, however.  */
  10215.     TYPE_VALUES (enumtype) = NULL_TREE;
  10216.  
  10217.   /* Initially, set up this enum as like `int'
  10218.      so that we can create the enumerators' declarations and values.
  10219.      Later on, the precision of the type may be changed and
  10220.      it may be laid out again.  */
  10221.  
  10222.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  10223.   TYPE_SIZE (enumtype) = NULL_TREE;
  10224.   fixup_unsigned_type (enumtype);
  10225.  
  10226.   /* We copy this value because enumerated type constants
  10227.      are really of the type of the enumerator, not integer_type_node.  */
  10228.   enum_next_value = copy_node (integer_zero_node);
  10229.   enum_overflow = 0;
  10230.  
  10231.   GNU_xref_decl (current_function_decl, enumtype);
  10232.   return enumtype;
  10233. }
  10234.  
  10235. /* After processing and defining all the values of an enumeration type,
  10236.    install their decls in the enumeration type and finish it off.
  10237.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  10238.    Returns ENUMTYPE.  */
  10239.  
  10240. tree
  10241. finish_enum (enumtype, values)
  10242.      register tree enumtype, values;
  10243. {
  10244.   register tree pair, tem;
  10245.   register HOST_WIDE_INT maxvalue = 0;
  10246.   register HOST_WIDE_INT minvalue = 0;
  10247.   register HOST_WIDE_INT i;
  10248.  
  10249.   /* Calculate the maximum value of any enumerator in this type.  */
  10250.  
  10251.   if (values)
  10252.     {
  10253.       /* Speed up the main loop by performing some precalculations */
  10254.  
  10255.       HOST_WIDE_INT value;
  10256.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  10257.       TREE_TYPE (DECL_INITIAL (TREE_VALUE (values))) = enumtype;
  10258.       TREE_VALUE (values) = DECL_INITIAL (TREE_VALUE (values));
  10259.       value = TREE_INT_CST_LOW (TREE_VALUE (values));
  10260.       minvalue = maxvalue = value;
  10261.       
  10262.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  10263.     {
  10264.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  10265.       TREE_TYPE (DECL_INITIAL (TREE_VALUE (pair))) = enumtype;
  10266.       TREE_VALUE (pair) = DECL_INITIAL (TREE_VALUE (pair));
  10267.       value = TREE_INT_CST_LOW (TREE_VALUE (pair));
  10268.       if (value > maxvalue)
  10269.         maxvalue = value;
  10270.       else if (value < minvalue)
  10271.         minvalue = value;
  10272.     }
  10273.     }
  10274.  
  10275.   TYPE_VALUES (enumtype) = values;
  10276.  
  10277.   if (flag_short_enums)
  10278.     {
  10279.       /* Determine the precision this type needs, lay it out, and define
  10280.          it.  */
  10281.  
  10282.       /* First reset precision */
  10283.       TYPE_PRECISION (enumtype) = 0;
  10284.  
  10285.       for (i = maxvalue; i; i >>= 1)
  10286.     TYPE_PRECISION (enumtype)++;
  10287.  
  10288.       if (!TYPE_PRECISION (enumtype))
  10289.     TYPE_PRECISION (enumtype) = 1;
  10290.  
  10291.       /* Cancel the laying out previously done for the enum type,
  10292.      so that fixup_unsigned_type will do it over.  */
  10293.       TYPE_SIZE (enumtype) = NULL_TREE;
  10294.  
  10295.       fixup_unsigned_type (enumtype);
  10296.     }
  10297.  
  10298.   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
  10299.  
  10300.   /* An enum can have some negative values; then it is signed.  */
  10301.   if (minvalue < 0)
  10302.     {
  10303.       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
  10304.       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
  10305.       TREE_UNSIGNED (enumtype) = 0;
  10306.     }
  10307.   if (flag_cadillac)
  10308.     cadillac_finish_enum (enumtype);
  10309.  
  10310.   /* Fix up all variant types of this enum type.  */
  10311.   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
  10312.     {
  10313.       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
  10314.       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
  10315.       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
  10316.       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
  10317.       TYPE_MODE (tem) = TYPE_MODE (enumtype);
  10318.       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
  10319.       TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
  10320.       TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
  10321.     }
  10322.  
  10323.   /* Finish debugging output for this type.  */
  10324. #if 0
  10325.   /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
  10326.      information should *not* be generated?  I think not.  */
  10327.   if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
  10328. #endif
  10329.     rest_of_type_compilation (enumtype, global_bindings_p ());
  10330.  
  10331.   return enumtype;
  10332. }
  10333.  
  10334. /* Build and install a CONST_DECL for one value of the
  10335.    current enumeration type (one that was begun with start_enum).
  10336.    Return a tree-list containing the name and its value.
  10337.    Assignment of sequential values by default is handled here.  */
  10338.  
  10339. tree
  10340. build_enumerator (name, value)
  10341.      tree name, value;
  10342. {
  10343.   tree decl, result;
  10344.   /* Change this to zero if we find VALUE is not shareable.  */
  10345.   int shareable = 1;
  10346.  
  10347.   /* Remove no-op casts from the value.  */
  10348.   if (value)
  10349.     STRIP_TYPE_NOPS (value);
  10350.  
  10351.   /* Validate and default VALUE.  */
  10352.   if (value != NULL_TREE)
  10353.     {
  10354.       if (TREE_READONLY_DECL_P (value))
  10355.     {
  10356.       value = decl_constant_value (value);
  10357.       shareable = 0;
  10358.     }
  10359.  
  10360.       if (TREE_CODE (value) == INTEGER_CST)
  10361.     {
  10362.       value = default_conversion (value);
  10363.       constant_expression_warning (value);
  10364.     }
  10365.       else
  10366.     {
  10367.       cp_error ("enumerator value for `%D' not integer constant", name);
  10368.       value = NULL_TREE;
  10369.     }
  10370.     }
  10371.  
  10372.   /* The order of things is reversed here so that we
  10373.      can check for possible sharing of enum values,
  10374.      to keep that from happening.  */
  10375.   /* Default based on previous value.  */
  10376.   if (value == NULL_TREE)
  10377.     {
  10378.       value = enum_next_value;
  10379.       if (enum_overflow)
  10380.     cp_error ("overflow in enumeration values at `%D'", name);
  10381.     }
  10382.  
  10383.   /* Remove no-op casts from the value.  */
  10384.   if (value)
  10385.     STRIP_TYPE_NOPS (value);
  10386.  
  10387.   /* Make up for hacks in lex.c.  */
  10388.   if (value == integer_zero_node)
  10389.     value = build_int_2 (0, 0);
  10390.   else if (value == integer_one_node)
  10391.     value = build_int_2 (1, 0);
  10392.   else if (TREE_CODE (value) == INTEGER_CST
  10393.        && (shareable == 0
  10394.            || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
  10395.     {
  10396.       value = copy_node (value);
  10397.       TREE_TYPE (value) = integer_type_node;
  10398.     }
  10399.  
  10400.   /* C++ associates enums with global, function, or class declarations.  */
  10401.  
  10402.   decl = current_scope ();
  10403.   if (decl && decl == current_class_type)
  10404.     {
  10405.       /* This enum declaration is local to the class, so we must put
  10406.      it in that class's list of decls.  */
  10407.       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
  10408.       DECL_INITIAL (decl) = value;
  10409.       TREE_READONLY (decl) = 1;
  10410.       pushdecl_class_level (decl);
  10411.       TREE_CHAIN (decl) = current_local_enum;
  10412.       current_local_enum = decl;
  10413.     }
  10414.   else
  10415.     {
  10416.       /* It's a global enum, or it's local to a function.  (Note local to
  10417.      a function could mean local to a class method.  */
  10418.       decl = build_decl (CONST_DECL, name, integer_type_node);
  10419.       DECL_INITIAL (decl) = value;
  10420.  
  10421.       pushdecl (decl);
  10422.       GNU_xref_decl (current_function_decl, decl);
  10423.     }
  10424.  
  10425.   /* Set basis for default for next value.  */
  10426.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  10427.                            integer_one_node, PLUS_EXPR);
  10428.   enum_overflow = tree_int_cst_lt (enum_next_value, value);
  10429.   
  10430.   if (enum_next_value == integer_one_node)
  10431.     enum_next_value = copy_node (enum_next_value);
  10432.  
  10433.   result = saveable_tree_cons (name, decl, NULL_TREE);
  10434.   return result;
  10435. }
  10436.  
  10437. tree
  10438. grok_enum_decls (type, decl)
  10439.      tree type, decl;
  10440. {
  10441.   tree d = current_local_enum;
  10442.   
  10443.   if (d == NULL_TREE)
  10444.     return decl;
  10445.   
  10446.   while (1)
  10447.     {
  10448.       TREE_TYPE (d) = type;
  10449.       if (TREE_CHAIN (d) == NULL_TREE)
  10450.     {
  10451.       TREE_CHAIN (d) = decl;
  10452.       break;
  10453.     }
  10454.       d = TREE_CHAIN (d);
  10455.     }
  10456.  
  10457.   decl = current_local_enum;
  10458.   current_local_enum = NULL_TREE;
  10459.   
  10460.   return decl;
  10461. }
  10462.  
  10463. /* Create the FUNCTION_DECL for a function definition.
  10464.    DECLSPECS and DECLARATOR are the parts of the declaration;
  10465.    they describe the function's name and the type it returns,
  10466.    but twisted together in a fashion that parallels the syntax of C.
  10467.  
  10468.    This function creates a binding context for the function body
  10469.    as well as setting up the FUNCTION_DECL in current_function_decl.
  10470.  
  10471.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  10472.    (it defines a datum instead), we return 0, which tells
  10473.    yyparse to report a parse error.
  10474.  
  10475.    For C++, we must first check whether that datum makes any sense.
  10476.    For example, "class A local_a(1,2);" means that variable local_a
  10477.    is an aggregate of type A, which should have a constructor
  10478.    applied to it with the argument list [1, 2].
  10479.  
  10480.    @@ There is currently no way to retrieve the storage
  10481.    @@ allocated to FUNCTION (or all of its parms) if we return
  10482.    @@ something we had previously.  */
  10483.  
  10484. int
  10485. start_function (declspecs, declarator, raises, pre_parsed_p)
  10486.      tree declarator, declspecs, raises;
  10487.      int pre_parsed_p;
  10488. {
  10489.   tree decl1, olddecl;
  10490.   tree ctype = NULL_TREE;
  10491.   tree fntype;
  10492.   tree restype;
  10493.   extern int have_extern_spec;
  10494.   extern int used_extern_spec;
  10495.   int doing_friend = 0;
  10496.  
  10497.   /* Sanity check.  */
  10498.   my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
  10499.   my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
  10500.  
  10501.   /* Assume, until we see it does. */
  10502.   current_function_returns_value = 0;
  10503.   current_function_returns_null = 0;
  10504.   warn_about_return_type = 0;
  10505.   current_extern_inline = 0;
  10506.   current_function_assigns_this = 0;
  10507.   current_function_just_assigned_this = 0;
  10508.   current_function_parms_stored = 0;
  10509.   original_result_rtx = NULL_RTX;
  10510.   current_function_obstack_index = 0;
  10511.   current_function_obstack_usage = 0;
  10512.  
  10513.   clear_temp_name ();
  10514.  
  10515.   /* This should only be done once on the top most decl. */
  10516.   if (have_extern_spec && !used_extern_spec)
  10517.     {
  10518.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
  10519.       used_extern_spec = 1;
  10520.     }
  10521.  
  10522.   if (pre_parsed_p)
  10523.     {
  10524.       decl1 = declarator;
  10525.  
  10526.       if (! DECL_ARGUMENTS (decl1)
  10527.       && !DECL_STATIC_FUNCTION_P (decl1)
  10528.       && DECL_CONTEXT (decl1)
  10529.       && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
  10530.       && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
  10531.     {
  10532.       cp_error ("redeclaration of `%#D'", decl1);
  10533.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
  10534.         cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
  10535.       else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
  10536.         cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
  10537.     }
  10538.  
  10539.       last_function_parms = DECL_ARGUMENTS (decl1);
  10540.       last_function_parm_tags = NULL_TREE;
  10541.       fntype = TREE_TYPE (decl1);
  10542.       if (TREE_CODE (fntype) == METHOD_TYPE)
  10543.     ctype = TYPE_METHOD_BASETYPE (fntype);
  10544.  
  10545.       /* ANSI C++ June 5 1992 WP 11.4.5.  A friend function defined in a
  10546.      class is in the (lexical) scope of the class in which it is
  10547.      defined.  */
  10548.       if (!ctype && DECL_FRIEND_P (decl1))
  10549.     {
  10550.       ctype = DECL_CLASS_CONTEXT (decl1);
  10551.  
  10552.       /* CTYPE could be null here if we're dealing with a template;
  10553.          for example, `inline friend float foo()' inside a template
  10554.          will have no CTYPE set.  */
  10555.       if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
  10556.         ctype = NULL_TREE;
  10557.       else
  10558.         doing_friend = 1;
  10559.     }
  10560.  
  10561.       if ( !(DECL_VINDEX (decl1)
  10562.          && write_virtuals >= 2
  10563.          && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
  10564.     current_extern_inline = DECL_THIS_EXTERN (decl1) && DECL_INLINE (decl1);
  10565.  
  10566.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  10567.  
  10568.       /* In a fcn definition, arg types must be complete.  */
  10569.       require_complete_types_for_parms (last_function_parms);
  10570.     }
  10571.   else
  10572.     {
  10573.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
  10574.       /* If the declarator is not suitable for a function definition,
  10575.      cause a syntax error.  */
  10576.       if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  10577.  
  10578.       fntype = TREE_TYPE (decl1);
  10579.  
  10580.       restype = TREE_TYPE (fntype);
  10581.       if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
  10582.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  10583.     {
  10584.       cp_error ("semicolon missing after declaration of `%#T'", restype);
  10585.       shadow_tag (build_tree_list (NULL_TREE, restype));
  10586.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  10587.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  10588.         fntype = build_function_type (integer_type_node,
  10589.                       TYPE_ARG_TYPES (fntype));
  10590.       else
  10591.         fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
  10592.                           integer_type_node,
  10593.                           TYPE_ARG_TYPES (fntype));
  10594.       TREE_TYPE (decl1) = fntype;
  10595.     }
  10596.  
  10597.       if (TREE_CODE (fntype) == METHOD_TYPE)
  10598.     ctype = TYPE_METHOD_BASETYPE (fntype);
  10599.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  10600.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
  10601.            && DECL_CONTEXT (decl1) == NULL_TREE)
  10602.     {
  10603.       /* If this doesn't return integer_type, complain.  */
  10604.       if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
  10605.         {
  10606.           if (pedantic || warn_return_type)
  10607.         warning ("return type for `main' changed to integer type");
  10608.           TREE_TYPE (decl1) = fntype = default_function_type;
  10609.         }
  10610.       warn_about_return_type = 0;
  10611.     }
  10612.     }
  10613.  
  10614.   /* Warn if function was previously implicitly declared
  10615.      (but not if we warned then).  */
  10616.   if (! warn_implicit
  10617.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
  10618.     cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
  10619.  
  10620.   current_function_decl = decl1;
  10621.  
  10622.   if (flag_cadillac)
  10623.     cadillac_start_function (decl1);
  10624.   else
  10625.     announce_function (decl1);
  10626.  
  10627.   if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
  10628.     {
  10629.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  10630.     error_with_aggr_type (TREE_TYPE (fntype),
  10631.                   "return-type `%s' is an incomplete type");
  10632.       else
  10633.     error ("return-type is an incomplete type");
  10634.  
  10635.       /* Make it return void instead, but don't change the
  10636.      type of the DECL_RESULT, in case we have a named return value.  */
  10637.       if (ctype)
  10638.     TREE_TYPE (decl1)
  10639.       = build_cplus_method_type (build_type_variant (ctype,
  10640.                              TREE_READONLY (decl1),
  10641.                              TREE_SIDE_EFFECTS (decl1)),
  10642.                      void_type_node,
  10643.                      FUNCTION_ARG_CHAIN (decl1));
  10644.       else
  10645.     TREE_TYPE (decl1)
  10646.       = build_function_type (void_type_node,
  10647.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  10648.       DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
  10649.     }
  10650.  
  10651.   if (warn_about_return_type)
  10652.     warning ("return-type defaults to `int'");
  10653.  
  10654.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  10655.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  10656.   DECL_INITIAL (decl1) = error_mark_node;
  10657.  
  10658.   /* Didn't get anything from C.  */
  10659.   olddecl = NULL_TREE;
  10660.  
  10661.   /* This function exists in static storage.
  10662.      (This does not mean `static' in the C sense!)  */
  10663.   TREE_STATIC (decl1) = 1;
  10664.  
  10665.   /* Record the decl so that the function name is defined.
  10666.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  10667.      use the old decl.  */
  10668.  
  10669.   if (pre_parsed_p == 0)
  10670.     {
  10671.       current_function_decl = decl1 = pushdecl (decl1);
  10672.       DECL_MAIN_VARIANT (decl1) = decl1;
  10673.       fntype = TREE_TYPE (decl1);
  10674.     }
  10675.   else
  10676.     current_function_decl = decl1;
  10677.  
  10678.   /* If this function belongs to an interface, it is public.
  10679.      If it belongs to someone else's interface, it is also external.
  10680.      It doesn't matter whether it's inline or not.  */
  10681.   if (interface_unknown == 0)
  10682.     {
  10683.       TREE_PUBLIC (decl1) = 1;
  10684.       DECL_EXTERNAL (decl1)
  10685.     = (interface_only
  10686.        || (DECL_INLINE (decl1) && ! flag_implement_inlines));
  10687.     }
  10688.   else if (DECL_EXPLICIT_INSTANTIATION (decl1))
  10689.     /* PUBLIC and EXTERNAL set by do_*_instantiation */;
  10690.   else
  10691.     {
  10692.       /* This is a definition, not a reference.
  10693.      So normally clear DECL_EXTERNAL.
  10694.      However, `extern inline' acts like a declaration except for
  10695.      defining how to inline.  So set DECL_EXTERNAL in that case.  */
  10696.       DECL_EXTERNAL (decl1) = current_extern_inline;
  10697.  
  10698.       DECL_DEFER_OUTPUT (decl1) = DECL_INLINE (decl1);
  10699.     }
  10700.  
  10701.   if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
  10702.     {
  10703.       if (TREE_CODE (fntype) == METHOD_TYPE)
  10704.     TREE_TYPE (decl1) = fntype
  10705.       = build_function_type (TREE_TYPE (fntype),
  10706.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  10707.       last_function_parms = TREE_CHAIN (last_function_parms);
  10708.       DECL_ARGUMENTS (decl1) = last_function_parms;
  10709.       ctype = NULL_TREE;
  10710.     }
  10711.   restype = TREE_TYPE (fntype);
  10712.  
  10713.   pushlevel (0);
  10714.   current_binding_level->parm_flag = 1;
  10715.  
  10716.   /* Save the parm names or decls from this function's declarator
  10717.      where store_parm_decls will find them.  */
  10718.   current_function_parms = last_function_parms;
  10719.   current_function_parm_tags = last_function_parm_tags;
  10720.  
  10721.   GNU_xref_function (decl1, current_function_parms);
  10722.  
  10723.   make_function_rtl (decl1);
  10724.  
  10725.   if (ctype)
  10726.     {
  10727.       push_nested_class (ctype, 1);
  10728.  
  10729.       /* If we're compiling a friend function, neither of the variables
  10730.      current_class_decl nor current_class_type will have values.  */
  10731.       if (! doing_friend)
  10732.     {
  10733.       /* We know that this was set up by `grokclassfn'.
  10734.          We do not wait until `store_parm_decls', since evil
  10735.          parse errors may never get us to that point.  Here
  10736.          we keep the consistency between `current_class_type'
  10737.          and `current_class_decl'.  */
  10738.       current_class_decl = last_function_parms;
  10739.       my_friendly_assert (current_class_decl != NULL_TREE
  10740.           && TREE_CODE (current_class_decl) == PARM_DECL, 162);
  10741.       if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
  10742.         {
  10743.           tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
  10744.           if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
  10745.         {
  10746.           /* Can't call build_indirect_ref here, because it has special
  10747.              logic to return C_C_D given this argument.  */
  10748.           C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
  10749.           CLASSTYPE_INST_VAR (ctype) = C_C_D;
  10750.         }
  10751.           else
  10752.         {
  10753.           C_C_D = CLASSTYPE_INST_VAR (ctype);
  10754.           /* `current_class_decl' is different for every
  10755.              function we compile.  */
  10756.           TREE_OPERAND (C_C_D, 0) = current_class_decl;
  10757.         }
  10758.           TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
  10759.           TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
  10760.           TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
  10761.         }
  10762.       else
  10763.         C_C_D = current_class_decl;
  10764.     }
  10765.     }
  10766.   else
  10767.     {
  10768.       if (DECL_STATIC_FUNCTION_P (decl1))
  10769.     push_nested_class (DECL_CONTEXT (decl1), 2);
  10770.       else
  10771.     push_memoized_context (0, 1);
  10772.     }
  10773.  
  10774.   /* Allocate further tree nodes temporarily during compilation
  10775.      of this function only.  Tiemann moved up here from bottom of fn.  */
  10776.   temporary_allocation ();
  10777.  
  10778.   /* Promote the value to int before returning it.  */
  10779.   if (C_PROMOTING_INTEGER_TYPE_P (restype))
  10780.     {
  10781.       /* It retains unsignedness if traditional or if it isn't
  10782.      really getting wider.  */
  10783.       if (TREE_UNSIGNED (restype)
  10784.       && (flag_traditional
  10785.           || TYPE_PRECISION (restype)
  10786.            == TYPE_PRECISION (integer_type_node)))
  10787.     restype = unsigned_type_node;
  10788.       else
  10789.     restype = integer_type_node;
  10790.     }
  10791.   if (DECL_RESULT (decl1) == NULL_TREE)
  10792.     DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
  10793.  
  10794.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
  10795.     {
  10796.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10797.       ctor_label = NULL_TREE;
  10798.     }
  10799.   else
  10800.     {
  10801.       dtor_label = NULL_TREE;
  10802.       if (DECL_CONSTRUCTOR_P (decl1))
  10803.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10804.     }
  10805.  
  10806.   /* If this fcn was already referenced via a block-scope `extern' decl
  10807.      (or an implicit decl), propagate certain information about the usage.  */
  10808.   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
  10809.     TREE_ADDRESSABLE (decl1) = 1;
  10810.  
  10811.   return 1;
  10812. }
  10813.  
  10814. /* Store the parameter declarations into the current function declaration.
  10815.    This is called after parsing the parameter declarations, before
  10816.    digesting the body of the function.
  10817.  
  10818.    Also install to binding contour return value identifier, if any.  */
  10819.  
  10820. void
  10821. store_parm_decls ()
  10822. {
  10823.   register tree fndecl = current_function_decl;
  10824.   register tree parm;
  10825.   int parms_have_cleanups = 0;
  10826.  
  10827.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  10828.   tree specparms = current_function_parms;
  10829.  
  10830.   /* This is a list of types declared among parms in a prototype.  */
  10831.   tree parmtags = current_function_parm_tags;
  10832.  
  10833.   /* This is a chain of any other decls that came in among the parm
  10834.      declarations.  If a parm is declared with  enum {foo, bar} x;
  10835.      then CONST_DECLs for foo and bar are put here.  */
  10836.   tree nonparms = NULL_TREE;
  10837.  
  10838.   if (current_binding_level == global_binding_level)
  10839.     fatal ("parse errors have confused me too much");
  10840.  
  10841.   /* Initialize RTL machinery.  */
  10842.   init_function_start (fndecl, input_filename, lineno);
  10843.  
  10844.   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
  10845.   declare_function_name ();
  10846.  
  10847.   /* Create a binding level for the parms.  */
  10848.   expand_start_bindings (0);
  10849.  
  10850.   if (specparms != NULL_TREE)
  10851.     {
  10852.       /* This case is when the function was defined with an ANSI prototype.
  10853.      The parms already have decls, so we need not do anything here
  10854.      except record them as in effect
  10855.      and complain if any redundant old-style parm decls were written.  */
  10856.  
  10857.       register tree next;
  10858.  
  10859.       /* Must clear this because it might contain TYPE_DECLs declared
  10860.      at class level.  */
  10861.       storedecls (NULL_TREE);
  10862.       for (parm = nreverse (specparms); parm; parm = next)
  10863.     {
  10864.       next = TREE_CHAIN (parm);
  10865.       if (TREE_CODE (parm) == PARM_DECL)
  10866.         {
  10867.           tree cleanup = maybe_build_cleanup (parm);
  10868.           if (DECL_NAME (parm) == NULL_TREE)
  10869.         {
  10870. #if 0
  10871.           cp_error_at ("parameter name omitted", parm);
  10872. #else
  10873.           /* for C++, this is not an error.  */
  10874.           pushdecl (parm);
  10875. #endif
  10876.         }
  10877.           else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  10878.         cp_error ("parameter `%D' declared void", parm);
  10879.           else
  10880.         {
  10881.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  10882.              A parameter is assumed not to have any side effects.
  10883.              If this should change for any reason, then this
  10884.              will have to wrap the bashed reference type in a save_expr.
  10885.              
  10886.              Also, if the parameter type is declared to be an X
  10887.              and there is an X(X&) constructor, we cannot lay it
  10888.              into the stack (any more), so we make this parameter
  10889.              look like it is really of reference type.  Functions
  10890.              which pass parameters to this function will know to
  10891.              create a temporary in their frame, and pass a reference
  10892.              to that.  */
  10893.  
  10894.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  10895.               && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  10896.             SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  10897.  
  10898.           pushdecl (parm);
  10899.         }
  10900.           if (cleanup)
  10901.         {
  10902.           expand_decl (parm);
  10903.           if (! expand_decl_cleanup (parm, cleanup))
  10904.             cp_error ("parser lost in parsing declaration of `%D'",
  10905.                   parm);
  10906.           parms_have_cleanups = 1;
  10907.         }
  10908.         }
  10909.       else
  10910.         {
  10911.           /* If we find an enum constant or a type tag,
  10912.          put it aside for the moment.  */
  10913.           TREE_CHAIN (parm) = NULL_TREE;
  10914.           nonparms = chainon (nonparms, parm);
  10915.         }
  10916.     }
  10917.  
  10918.       /* Get the decls in their original chain order
  10919.      and record in the function.  This is all and only the
  10920.      PARM_DECLs that were pushed into scope by the loop above.  */
  10921.       DECL_ARGUMENTS (fndecl) = getdecls ();
  10922.  
  10923.       storetags (chainon (parmtags, gettags ()));
  10924.     }
  10925.   else
  10926.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  10927.  
  10928.   /* Now store the final chain of decls for the arguments
  10929.      as the decl-chain of the current lexical scope.
  10930.      Put the enumerators in as well, at the front so that
  10931.      DECL_ARGUMENTS is not modified.  */
  10932.  
  10933.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  10934.  
  10935.   /* Initialize the RTL code for the function.  */
  10936.   DECL_SAVED_INSNS (fndecl) = NULL_RTX;
  10937.   expand_function_start (fndecl, parms_have_cleanups);
  10938.  
  10939.   /* Create a binding contour which can be used to catch
  10940.      cleanup-generated temporaries.  Also, if the return value needs or
  10941.      has initialization, deal with that now.  */
  10942.   if (parms_have_cleanups)
  10943.     {
  10944.       pushlevel (0);
  10945.       expand_start_bindings (0);
  10946.     }
  10947.  
  10948.   current_function_parms_stored = 1;
  10949.  
  10950.   if (flag_gc)
  10951.     {
  10952.       maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
  10953.       if (! expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
  10954.     cp_error ("parser lost in parsing declaration of `%D'", fndecl);
  10955.     }
  10956.  
  10957.   /* If this function is `main', emit a call to `__main'
  10958.      to run global initializers, etc.  */
  10959.   if (DECL_NAME (fndecl)
  10960.       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  10961.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  10962.       && DECL_CONTEXT (fndecl) == NULL_TREE)
  10963.     {
  10964.       expand_main_function ();
  10965.  
  10966.       if (flag_gc)
  10967.     expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
  10968.              0, VOIDmode, 0);
  10969.  
  10970.       if (flag_dossier)
  10971.     output_builtin_tdesc_entries ();
  10972.     }
  10973. }
  10974.  
  10975. /* Bind a name and initialization to the return value of
  10976.    the current function.  */
  10977. void
  10978. store_return_init (return_id, init)
  10979.      tree return_id, init;
  10980. {
  10981.   tree decl = DECL_RESULT (current_function_decl);
  10982.  
  10983.   if (flag_ansi)
  10984.     /* Give this error as many times as there are occurrences,
  10985.        so that users can use Emacs compilation buffers to find
  10986.        and fix all such places.  */
  10987.     pedwarn ("ANSI C++ does not permit named return values");
  10988.  
  10989.   if (return_id != NULL_TREE)
  10990.     {
  10991.       if (DECL_NAME (decl) == NULL_TREE)
  10992.     {
  10993.       DECL_NAME (decl) = return_id;
  10994.       DECL_ASSEMBLER_NAME (decl) = return_id;
  10995.     }
  10996.       else
  10997.     error ("return identifier `%s' already in place",
  10998.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  10999.     }
  11000.  
  11001.   /* Can't let this happen for constructors.  */
  11002.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  11003.     {
  11004.       error ("can't redefine default return value for constructors");
  11005.       return;
  11006.     }
  11007.  
  11008.   /* If we have a named return value, put that in our scope as well.  */
  11009.   if (DECL_NAME (decl) != NULL_TREE)
  11010.     {
  11011.       /* If this named return value comes in a register,
  11012.      put it in a pseudo-register.  */
  11013.       if (DECL_REGISTER (decl))
  11014.     {
  11015.       original_result_rtx = DECL_RTL (decl);
  11016.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  11017.     }
  11018.  
  11019.       /* Let `finish_decl' know that this initializer is ok.  */
  11020.       DECL_INITIAL (decl) = init;
  11021.       pushdecl (decl);
  11022.       finish_decl (decl, init, 0, 0);
  11023.     }
  11024. }
  11025.  
  11026. #if 0
  11027. /* Generate code for default X() constructor.  */
  11028. static void
  11029. build_default_constructor (fndecl)
  11030.      tree fndecl;
  11031. {
  11032.   int i = CLASSTYPE_N_BASECLASSES (current_class_type);
  11033.   tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
  11034.   tree fields = TYPE_FIELDS (current_class_type);
  11035.   tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
  11036.  
  11037.   if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  11038.     parm = TREE_CHAIN (parm);
  11039.   parm = DECL_REFERENCE_SLOT (parm);
  11040.  
  11041.   while (--i >= 0)
  11042.     {
  11043.       tree basetype = TREE_VEC_ELT (binfos, i);
  11044.       if (TYPE_HAS_INIT_REF (basetype))
  11045.     {
  11046.       tree name = TYPE_NAME (basetype);
  11047.       if (TREE_CODE (name) == TYPE_DECL)
  11048.         name = DECL_NAME (name);
  11049.       current_base_init_list = tree_cons (name, parm, current_base_init_list);
  11050.     }
  11051.     }
  11052.   for (; fields; fields = TREE_CHAIN (fields))
  11053.     {
  11054.       tree name, init;
  11055.       if (TREE_STATIC (fields))
  11056.     continue;
  11057.       if (TREE_CODE (fields) != FIELD_DECL)
  11058.     continue;
  11059.       if (DECL_NAME (fields))
  11060.     {
  11061.       if (VFIELD_NAME_P (DECL_NAME (fields)))
  11062.         continue;
  11063.       if (VBASE_NAME_P (DECL_NAME (fields)))
  11064.         continue;
  11065.  
  11066.       /* True for duplicate members.  */
  11067.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
  11068.         continue;
  11069.     }
  11070.  
  11071.       init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
  11072.       init = build_tree_list (NULL_TREE, init);
  11073.  
  11074.       current_member_init_list
  11075.     = tree_cons (DECL_NAME (fields), init, current_member_init_list);
  11076.     }
  11077. }
  11078. #endif
  11079.  
  11080. /* Finish up a function declaration and compile that function
  11081.    all the way to assembler language output.  The free the storage
  11082.    for the function definition.
  11083.  
  11084.    This is called after parsing the body of the function definition.
  11085.    LINENO is the current line number.
  11086.  
  11087.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  11088.    (and expand_end_bindings) must be made to take care of the binding
  11089.    contour for the base initializers.  This is only relevant for
  11090.    constructors.  */
  11091.  
  11092. void
  11093. finish_function (lineno, call_poplevel)
  11094.      int lineno;
  11095.      int call_poplevel;
  11096. {
  11097.   register tree fndecl = current_function_decl;
  11098.   tree fntype, ctype = NULL_TREE;
  11099.   rtx head, last_parm_insn, mark;
  11100.   /* Label to use if this function is supposed to return a value.  */
  11101.   tree no_return_label = NULL_TREE;
  11102.   tree decls = NULL_TREE;
  11103.  
  11104.   /* When we get some parse errors, we can end up without a
  11105.      current_function_decl, so cope.  */
  11106.   if (fndecl == NULL_TREE)
  11107.     return;
  11108.  
  11109.   fntype = TREE_TYPE (fndecl);
  11110.  
  11111. /*  TREE_READONLY (fndecl) = 1;
  11112.     This caused &foo to be of type ptr-to-const-function
  11113.     which then got a warning when stored in a ptr-to-function variable.  */
  11114.  
  11115.   /* This happens on strange parse errors.  */
  11116.   if (! current_function_parms_stored)
  11117.     {
  11118.       call_poplevel = 0;
  11119.       store_parm_decls ();
  11120.     }
  11121.  
  11122.   if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE)
  11123.     {
  11124.       tree ttype = target_type (fntype);
  11125.       tree parmdecl;
  11126.  
  11127.       if (IS_AGGR_TYPE (ttype))
  11128.     /* Let debugger know it should output info for this type.  */
  11129.     note_debug_info_needed (ttype);
  11130.  
  11131.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  11132.     {
  11133.       ttype = target_type (TREE_TYPE (parmdecl));
  11134.       if (IS_AGGR_TYPE (ttype))
  11135.         /* Let debugger know it should output info for this type.  */
  11136.         note_debug_info_needed (ttype);
  11137.     }
  11138.     }
  11139.  
  11140.   /* Clean house because we will need to reorder insns here.  */
  11141.   do_pending_stack_adjust ();
  11142.  
  11143.   if (dtor_label)
  11144.     {
  11145.       tree binfo = TYPE_BINFO (current_class_type);
  11146.       tree cond = integer_one_node;
  11147.       tree exprstmt, vfields;
  11148.       tree in_charge_node = lookup_name (in_charge_identifier, 0);
  11149.       tree virtual_size;
  11150.       int ok_to_optimize_dtor = 0;
  11151.  
  11152.       if (current_function_assigns_this)
  11153.     cond = build (NE_EXPR, integer_type_node,
  11154.               current_class_decl, integer_zero_node);
  11155.       else
  11156.     {
  11157.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  11158.  
  11159.       /* If this destructor is empty, then we don't need to check
  11160.          whether `this' is NULL in some cases.  */
  11161.       mark = get_last_insn ();
  11162.       last_parm_insn = get_first_nonparm_insn ();
  11163.  
  11164.       if ((flag_this_is_variable & 1) == 0)
  11165.         ok_to_optimize_dtor = 1;
  11166.       else if (mark == last_parm_insn)
  11167.         ok_to_optimize_dtor
  11168.           = (n_baseclasses == 0
  11169.          || (n_baseclasses == 1
  11170.              && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
  11171.     }
  11172.  
  11173.       /* These initializations might go inline.  Protect
  11174.      the binding level of the parms.  */
  11175.       pushlevel (0);
  11176.       expand_start_bindings (0);
  11177.  
  11178.       if (current_function_assigns_this)
  11179.     {
  11180.       current_function_assigns_this = 0;
  11181.       current_function_just_assigned_this = 0;
  11182.     }
  11183.  
  11184.       /* Generate the code to call destructor on base class.
  11185.      If this destructor belongs to a class with virtual
  11186.      functions, then set the virtual function table
  11187.      pointer to represent the type of our base class.  */
  11188.  
  11189.       /* This side-effect makes call to `build_delete' generate the
  11190.      code we have to have at the end of this destructor.  */
  11191.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  11192.  
  11193.       /* These are two cases where we cannot delegate deletion.  */
  11194.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  11195.       || TYPE_GETS_REG_DELETE (current_class_type))
  11196.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  11197.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  11198.       else
  11199.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  11200.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  11201.  
  11202.       /* If we did not assign to this, then `this' is non-zero at
  11203.      the end of a destructor.  As a special optimization, don't
  11204.      emit test if this is an empty destructor.  If it does nothing,
  11205.      it does nothing.  If it calls a base destructor, the base
  11206.      destructor will perform the test.  */
  11207.  
  11208.       if (exprstmt != error_mark_node
  11209.       && (TREE_CODE (exprstmt) != NOP_EXPR
  11210.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  11211.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  11212.     {
  11213.       expand_label (dtor_label);
  11214.       if (cond != integer_one_node)
  11215.         expand_start_cond (cond, 0);
  11216.       if (exprstmt != void_zero_node)
  11217.         /* Don't call `expand_expr_stmt' if we're not going to do
  11218.            anything, since -Wall will give a diagnostic.  */
  11219.         expand_expr_stmt (exprstmt);
  11220.  
  11221.       /* Run destructor on all virtual baseclasses.  */
  11222.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  11223.         {
  11224.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  11225.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  11226.                     in_charge_node, integer_two_node), 0);
  11227.           while (vbases)
  11228.         {
  11229.           if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
  11230.             {
  11231.               tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
  11232.               expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
  11233.                               ptr, integer_zero_node,
  11234.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
  11235.             }
  11236.           vbases = TREE_CHAIN (vbases);
  11237.         }
  11238.           expand_end_cond ();
  11239.         }
  11240.  
  11241.       do_pending_stack_adjust ();
  11242.       if (cond != integer_one_node)
  11243.         expand_end_cond ();
  11244.     }
  11245.  
  11246.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  11247.  
  11248.       virtual_size = c_sizeof (current_class_type);
  11249.  
  11250.       /* At the end, call delete if that's what's requested.  */
  11251.       if (TYPE_GETS_REG_DELETE (current_class_type))
  11252.     /* This NOP_EXPR means we are in a static call context.  */
  11253.     exprstmt =
  11254.       build_method_call
  11255.         (build_indirect_ref
  11256.          (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
  11257.               error_mark_node),
  11258.           NULL_PTR),
  11259.          ansi_opname[(int) DELETE_EXPR],
  11260.          tree_cons (NULL_TREE, current_class_decl,
  11261.             build_tree_list (NULL_TREE, virtual_size)),
  11262.          NULL_TREE, LOOKUP_NORMAL);
  11263.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  11264.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
  11265.                    virtual_size);
  11266.       else
  11267.     exprstmt = NULL_TREE;
  11268.  
  11269.       if (exprstmt)
  11270.     {
  11271.       cond = build (BIT_AND_EXPR, integer_type_node,
  11272.             in_charge_node, integer_one_node);
  11273.       expand_start_cond (cond, 0);
  11274.       expand_expr_stmt (exprstmt);
  11275.       expand_end_cond ();
  11276.     }
  11277.  
  11278.       /* End of destructor.  */
  11279.       expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
  11280.       poplevel (2, 0, 0); /* XXX change to 1 */
  11281.  
  11282.       /* Back to the top of destructor.  */
  11283.       /* Dont execute destructor code if `this' is NULL.  */
  11284.       mark = get_last_insn ();
  11285.       last_parm_insn = get_first_nonparm_insn ();
  11286.       if (last_parm_insn == NULL_RTX)
  11287.     last_parm_insn = mark;
  11288.       else
  11289.     last_parm_insn = previous_insn (last_parm_insn);
  11290.  
  11291.       /* Make all virtual function table pointers in non-virtual base
  11292.      classes point to CURRENT_CLASS_TYPE's virtual function
  11293.      tables.  */
  11294.       expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
  11295.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  11296.     expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
  11297.       if (! ok_to_optimize_dtor)
  11298.     {
  11299.       cond = build_binary_op (NE_EXPR,
  11300.                   current_class_decl, integer_zero_node, 1);
  11301.       expand_start_cond (cond, 0);
  11302.     }
  11303.       if (mark != get_last_insn ())
  11304.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  11305.       if (! ok_to_optimize_dtor)
  11306.     expand_end_cond ();
  11307.     }
  11308.   else if (current_function_assigns_this)
  11309.     {
  11310.       /* Does not need to call emit_base_init, because
  11311.      that is done (if needed) just after assignment to this
  11312.      is seen.  */
  11313.  
  11314.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  11315.     {
  11316.       expand_label (ctor_label);
  11317.       ctor_label = NULL_TREE;
  11318.  
  11319.       if (call_poplevel)
  11320.         {
  11321.           decls = getdecls ();
  11322.           expand_end_bindings (decls, decls != NULL_TREE, 0);
  11323.           poplevel (decls != NULL_TREE, 0, 0);
  11324.         }
  11325.       c_expand_return (current_class_decl);
  11326.     }
  11327.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (
  11328.             DECL_RESULT (current_function_decl))) != void_type_node
  11329.            && return_label != NULL_RTX)
  11330.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11331.  
  11332.       current_function_assigns_this = 0;
  11333.       current_function_just_assigned_this = 0;
  11334.       base_init_insns = NULL_RTX;
  11335.     }
  11336.   else if (DECL_CONSTRUCTOR_P (fndecl))
  11337.     {
  11338.       tree allocated_this;
  11339.       tree cond, thenclause;
  11340.       /* Allow constructor for a type to get a new instance of the object
  11341.      using `build_new'.  */
  11342.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  11343.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  11344.  
  11345.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  11346.  
  11347.       if (flag_this_is_variable > 0)
  11348.     {
  11349.       cond = build_binary_op (EQ_EXPR,
  11350.                   current_class_decl, integer_zero_node, 1);
  11351.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  11352.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  11353.     }
  11354.  
  11355.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  11356.  
  11357.       /* must keep the first insn safe.  */
  11358.       head = get_insns ();
  11359.  
  11360.       /* this note will come up to the top with us.  */
  11361.       mark = get_last_insn ();
  11362.  
  11363.       if (flag_this_is_variable > 0)
  11364.     {
  11365.       expand_start_cond (cond, 0);
  11366.       expand_expr_stmt (thenclause);
  11367.       expand_end_cond ();
  11368.     }
  11369.  
  11370. #if 0
  11371.       if (DECL_NAME (fndecl) == NULL_TREE
  11372.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  11373.     build_default_constructor (fndecl);
  11374. #endif
  11375.  
  11376.       /* Emit insns from `emit_base_init' which sets up virtual
  11377.      function table pointer(s).  */
  11378.       emit_insns (base_init_insns);
  11379.       base_init_insns = NULL_RTX;
  11380.  
  11381.       /* This is where the body of the constructor begins.
  11382.      If there were no insns in this function body, then the
  11383.      last_parm_insn is also the last insn.
  11384.  
  11385.      If optimization is enabled, last_parm_insn may move, so
  11386.      we don't hold on to it (across emit_base_init).  */
  11387.       last_parm_insn = get_first_nonparm_insn ();
  11388.       if (last_parm_insn == NULL_RTX)
  11389.     last_parm_insn = mark;
  11390.       else
  11391.     last_parm_insn = previous_insn (last_parm_insn);
  11392.  
  11393.       if (mark != get_last_insn ())
  11394.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  11395.  
  11396.       /* This is where the body of the constructor ends.  */
  11397.       expand_label (ctor_label);
  11398.       ctor_label = NULL_TREE;
  11399.  
  11400.       if (call_poplevel)
  11401.     {
  11402.       expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
  11403.       poplevel (decls != NULL_TREE, 1, 0);
  11404.     }
  11405.  
  11406.       c_expand_return (current_class_decl);
  11407.  
  11408.       current_function_assigns_this = 0;
  11409.       current_function_just_assigned_this = 0;
  11410.     }
  11411.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  11412.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
  11413.        && DECL_CONTEXT (fndecl) == NULL_TREE)
  11414.     {
  11415.       /* Make it so that `main' always returns 0 by default.  */
  11416. #ifdef VMS
  11417.       c_expand_return (integer_one_node);
  11418. #else
  11419.       c_expand_return (integer_zero_node);
  11420. #endif
  11421.     }
  11422.   else if (return_label != NULL_RTX
  11423.        && current_function_return_value == NULL_TREE
  11424.        && ! DECL_NAME (DECL_RESULT (current_function_decl)))
  11425.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11426.  
  11427.   if (flag_gc)
  11428.     expand_gc_prologue_and_epilogue ();
  11429.  
  11430.   /* That's the end of the vtable decl's life.  Need to mark it such
  11431.      if doing stupid register allocation.
  11432.  
  11433.      Note that current_vtable_decl is really an INDIRECT_REF
  11434.      on top of a VAR_DECL here.  */
  11435.   if (obey_regdecls && current_vtable_decl)
  11436.     use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
  11437.  
  11438.   /* If this function is supposed to return a value, ensure that
  11439.      we do not fall into the cleanups by mistake.  The end of our
  11440.      function will look like this:
  11441.  
  11442.     user code (may have return stmt somewhere)
  11443.     goto no_return_label
  11444.     cleanup_label:
  11445.     cleanups
  11446.     goto return_label
  11447.     no_return_label:
  11448.     NOTE_INSN_FUNCTION_END
  11449.     return_label:
  11450.     things for return
  11451.  
  11452.      If the user omits a return stmt in the USER CODE section, we
  11453.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  11454.      Otherwise, we won't.  */
  11455.   if (no_return_label)
  11456.     {
  11457.       DECL_CONTEXT (no_return_label) = fndecl;
  11458.       DECL_INITIAL (no_return_label) = error_mark_node;
  11459.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  11460.       DECL_SOURCE_LINE (no_return_label) = lineno;
  11461.       expand_goto (no_return_label);
  11462.     }
  11463.  
  11464.   if (cleanup_label)
  11465.     {
  11466.       /* remove the binding contour which is used
  11467.      to catch cleanup-generated temporaries.  */
  11468.       expand_end_bindings (0, 0, 0);
  11469.       poplevel (0, 0, 0);
  11470.     }
  11471.  
  11472.   if (cleanup_label)
  11473.     /* Emit label at beginning of cleanup code for parameters.  */
  11474.     emit_label (cleanup_label);
  11475.  
  11476.   /* Get return value into register if that's where it's supposed to be.  */
  11477.   if (original_result_rtx)
  11478.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  11479.  
  11480.   /* Finish building code that will trigger warnings if users forget
  11481.      to make their functions return values.  */
  11482.   if (no_return_label || cleanup_label)
  11483.     emit_jump (return_label);
  11484.   if (no_return_label)
  11485.     {
  11486.       /* We don't need to call `expand_*_return' here because we
  11487.      don't need any cleanups here--this path of code is only
  11488.      for error checking purposes.  */
  11489.       expand_label (no_return_label);
  11490.     }
  11491.  
  11492.   /* reset scope for C++: if we were in the scope of a class,
  11493.      then when we finish this function, we are not longer so.
  11494.      This cannot be done until we know for sure that no more
  11495.      class members will ever be referenced in this function
  11496.      (i.e., calls to destructors).  */
  11497.   if (current_class_name)
  11498.     {
  11499.       ctype = current_class_type;
  11500.       pop_nested_class (1);
  11501.     }
  11502.   else
  11503.     pop_memoized_context (1);
  11504.  
  11505.   /* Generate rtl for function exit.  */
  11506.   expand_function_end (input_filename, lineno, 1);
  11507.  
  11508.   if (flag_handle_exceptions)
  11509.     expand_exception_blocks();
  11510.  
  11511.   /* This must come after expand_function_end because cleanups might
  11512.      have declarations (from inline functions) that need to go into
  11513.      this function's blocks.  */
  11514.   if (current_binding_level->parm_flag != 1)
  11515.     my_friendly_abort (122);
  11516.   poplevel (1, 0, 1);
  11517.  
  11518.   /* Must mark the RESULT_DECL as being in this function.  */
  11519.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  11520.  
  11521.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  11522.   if (flag_traditional && current_function_calls_setjmp)
  11523.     setjmp_protect (DECL_INITIAL (fndecl));
  11524.  
  11525.   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
  11526.      to the FUNCTION_DECL node itself.  */
  11527.   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
  11528.  
  11529.   /* So we can tell if jump_optimize sets it to 1.  */
  11530.   can_reach_end = 0;
  11531.  
  11532.   /* ??? Compensate for Sun brain damage in dealing with data segments
  11533.      of PIC code.  */
  11534.   if (flag_pic
  11535.       && (DECL_CONSTRUCTOR_P (fndecl)
  11536.       || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
  11537.       && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
  11538.     DECL_INLINE (fndecl) = 0;
  11539.  
  11540.   if (DECL_EXTERNAL (fndecl)
  11541.       /* This function is just along for the ride.  If we can make
  11542.      it inline, that's great.  Otherwise, just punt it.  */
  11543.       && (DECL_INLINE (fndecl) == 0
  11544.       || flag_no_inline
  11545.       || function_cannot_inline_p (fndecl)))
  11546.     {
  11547.       extern int rtl_dump_and_exit;
  11548.       int old_rtl_dump_and_exit = rtl_dump_and_exit;
  11549.       int inline_spec = DECL_INLINE (fndecl);
  11550.  
  11551.       /* This throws away the code for FNDECL.  */
  11552.       rtl_dump_and_exit = 1;
  11553.       /* This throws away the memory of the code for FNDECL.  */
  11554.       if (flag_no_inline)
  11555.     DECL_INLINE (fndecl) = 0;
  11556.       rest_of_compilation (fndecl);
  11557.       rtl_dump_and_exit = old_rtl_dump_and_exit;
  11558.       DECL_INLINE (fndecl) = inline_spec;
  11559.     }
  11560.   else
  11561.     {
  11562.       /* Run the optimizers and output the assembler code for this
  11563.          function.  */
  11564.       rest_of_compilation (fndecl);
  11565.     }
  11566.  
  11567.   if (DECL_INLINE (fndecl)
  11568.       && !TREE_ASM_WRITTEN (fndecl) && DECL_FUNCTION_MEMBER_P (fndecl))
  11569.     {
  11570.       mark_inline_for_output (fndecl);
  11571.     }
  11572.  
  11573.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  11574.     note_debug_info_needed (ctype);
  11575.  
  11576.   current_function_returns_null |= can_reach_end;
  11577.  
  11578.   /* Since we don't normally go through c_expand_return for constructors,
  11579.      this normally gets the wrong value.
  11580.      Also, named return values have their return codes emitted after
  11581.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  11582.   if (DECL_CONSTRUCTOR_P (fndecl)
  11583.       || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
  11584.     current_function_returns_null = 0;
  11585.  
  11586.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  11587.     cp_warning ("`noreturn' function `%D' does return", fndecl);
  11588.   else if ((warn_return_type || pedantic)
  11589.        && current_function_returns_null
  11590.        && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
  11591.     {
  11592.       /* If this function returns non-void and control can drop through,
  11593.      complain.  */
  11594.       cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
  11595.     }
  11596.   /* With just -W, complain only if function returns both with
  11597.      and without a value.  */
  11598.   else if (extra_warnings
  11599.        && current_function_returns_value && current_function_returns_null)
  11600.     warning ("this function may return with or without a value");
  11601.  
  11602.   /* Free all the tree nodes making up this function.  */
  11603.   /* Switch back to allocating nodes permanently
  11604.      until we start another function.  */
  11605.   permanent_allocation (1);
  11606.  
  11607.   if (flag_cadillac)
  11608.     cadillac_finish_function (fndecl);
  11609.  
  11610.   if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
  11611.     {
  11612.       /* Stop pointing to the local nodes about to be freed.  */
  11613.       /* But DECL_INITIAL must remain nonzero so we know this
  11614.      was an actual function definition.  */
  11615.       DECL_INITIAL (fndecl) = error_mark_node;
  11616.       if (! DECL_CONSTRUCTOR_P (fndecl)
  11617.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  11618.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  11619.     }
  11620.  
  11621.   /* Let the error reporting routines know that we're outside a function.  */
  11622.   current_function_decl = NULL_TREE;
  11623.   named_label_uses = NULL_TREE;
  11624. }
  11625.  
  11626. /* Create the FUNCTION_DECL for a function definition.
  11627.    LINE1 is the line number that the definition absolutely begins on.
  11628.    LINE2 is the line number that the name of the function appears on.
  11629.    DECLSPECS and DECLARATOR are the parts of the declaration;
  11630.    they describe the return type and the name of the function,
  11631.    but twisted together in a fashion that parallels the syntax of C.
  11632.  
  11633.    This function creates a binding context for the function body
  11634.    as well as setting up the FUNCTION_DECL in current_function_decl.
  11635.  
  11636.    Returns a FUNCTION_DECL on success.
  11637.  
  11638.    If the DECLARATOR is not suitable for a function (it defines a datum
  11639.    instead), we return 0, which tells yyparse to report a parse error.
  11640.  
  11641.    May return void_type_node indicating that this method is actually
  11642.    a friend.  See grokfield for more details.
  11643.  
  11644.    Came here with a `.pushlevel' .
  11645.  
  11646.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  11647.    CHANGES TO CODE IN `grokfield'.  */
  11648. tree
  11649. start_method (declspecs, declarator, raises)
  11650.      tree declarator, declspecs, raises;
  11651. {
  11652.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
  11653.  
  11654.   /* Something too ugly to handle.  */
  11655.   if (fndecl == NULL_TREE)
  11656.     return NULL_TREE;
  11657.  
  11658.   /* Pass friends other than inline friend functions back.  */
  11659.   if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
  11660.     return fndecl;
  11661.  
  11662.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  11663.     /* Not a function, tell parser to report parse error.  */
  11664.     return NULL_TREE;
  11665.  
  11666.   if (IS_SIGNATURE (current_class_type))
  11667.     {
  11668.       IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
  11669.       /* In case we need this info later.  */
  11670.       HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
  11671.     }
  11672.  
  11673.   if (DECL_IN_AGGR_P (fndecl))
  11674.     {
  11675.       if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
  11676.     {
  11677.       if (DECL_CONTEXT (fndecl))
  11678.         cp_error ("`%D' is already defined in class %s", fndecl,
  11679.                  TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
  11680.     }
  11681.       return void_type_node;
  11682.     }
  11683.  
  11684.   if (flag_default_inline)
  11685.     DECL_INLINE (fndecl) = 1;
  11686.  
  11687.   if (processing_template_defn)
  11688.     SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
  11689.  
  11690.   /* We read in the parameters on the maybepermanent_obstack,
  11691.      but we won't be getting back to them until after we
  11692.      may have clobbered them.  So the call to preserve_data
  11693.      will keep them safe.  */
  11694.   preserve_data ();
  11695.  
  11696.   if (! DECL_FRIEND_P (fndecl))
  11697.     {
  11698.       if (DECL_CHAIN (fndecl) != NULL_TREE)
  11699.     {
  11700.       /* Need a fresh node here so that we don't get circularity
  11701.          when we link these together.  If FNDECL was a friend, then
  11702.          `pushdecl' does the right thing, which is nothing wrt its
  11703.          current value of DECL_CHAIN.  */
  11704.       fndecl = copy_node (fndecl);
  11705.     }
  11706.       if (TREE_CHAIN (fndecl))
  11707.     {
  11708.       fndecl = copy_node (fndecl);
  11709.       TREE_CHAIN (fndecl) = NULL_TREE;
  11710.     }
  11711.  
  11712.       if (DECL_CONSTRUCTOR_P (fndecl))
  11713.     {
  11714.       if (! grok_ctor_properties (current_class_type, fndecl))
  11715.         return void_type_node;
  11716.     }
  11717.       else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
  11718.     grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
  11719.     }
  11720.  
  11721.   finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
  11722.  
  11723.   /* Make a place for the parms */
  11724.   pushlevel (0);
  11725.   current_binding_level->parm_flag = 1;
  11726.   
  11727.   DECL_IN_AGGR_P (fndecl) = 1;
  11728.   return fndecl;
  11729. }
  11730.  
  11731. /* Go through the motions of finishing a function definition.
  11732.    We don't compile this method until after the whole class has
  11733.    been processed.
  11734.  
  11735.    FINISH_METHOD must return something that looks as though it
  11736.    came from GROKFIELD (since we are defining a method, after all).
  11737.  
  11738.    This is called after parsing the body of the function definition.
  11739.    STMTS is the chain of statements that makes up the function body.
  11740.  
  11741.    DECL is the ..._DECL that `start_method' provided.  */
  11742.  
  11743. tree
  11744. finish_method (decl)
  11745.      tree decl;
  11746. {
  11747.   register tree fndecl = decl;
  11748.   tree old_initial;
  11749.  
  11750.   register tree link;
  11751.  
  11752.   if (TYPE_MAIN_VARIANT (decl) == void_type_node)
  11753.     return decl;
  11754.  
  11755.   old_initial = DECL_INITIAL (fndecl);
  11756.  
  11757.   /* Undo the level for the parms (from start_method).
  11758.      This is like poplevel, but it causes nothing to be
  11759.      saved.  Saving information here confuses symbol-table
  11760.      output routines.  Besides, this information will
  11761.      be correctly output when this method is actually
  11762.      compiled.  */
  11763.  
  11764.   /* Clear out the meanings of the local variables of this level;
  11765.      also record in each decl which block it belongs to.  */
  11766.  
  11767.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  11768.     {
  11769.       if (DECL_NAME (link) != NULL_TREE)
  11770.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  11771.       my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
  11772.       DECL_CONTEXT (link) = NULL_TREE;
  11773.     }
  11774.  
  11775.   /* Restore all name-meanings of the outer levels
  11776.      that were shadowed by this level.  */
  11777.  
  11778.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  11779.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11780.   for (link = current_binding_level->class_shadowed;
  11781.        link; link = TREE_CHAIN (link))
  11782.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11783.   for (link = current_binding_level->type_shadowed;
  11784.        link; link = TREE_CHAIN (link))
  11785.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11786.  
  11787.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  11788.               (HOST_WIDE_INT) current_binding_level->level_chain,
  11789.               current_binding_level->parm_flag,
  11790.               current_binding_level->keep,
  11791.               current_binding_level->tag_transparent);
  11792.  
  11793.   poplevel (0, 0, 0);
  11794.  
  11795.   DECL_INITIAL (fndecl) = old_initial;
  11796.  
  11797.   /* We used to check if the context of FNDECL was different from
  11798.      current_class_type as another way to get inside here.  This didn't work
  11799.      for String.cc in libg++.  */
  11800.   if (DECL_FRIEND_P (fndecl))
  11801.     {
  11802.       CLASSTYPE_INLINE_FRIENDS (current_class_type)
  11803.     = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  11804.       decl = void_type_node;
  11805.     }
  11806.  
  11807.   return decl;
  11808. }
  11809.  
  11810. /* Called when a new struct TYPE is defined.
  11811.    If this structure or union completes the type of any previous
  11812.    variable declaration, lay it out and output its rtl.  */
  11813.  
  11814. void
  11815. hack_incomplete_structures (type)
  11816.      tree type;
  11817. {
  11818.   tree decl;
  11819.  
  11820.   if (current_binding_level->n_incomplete == 0)
  11821.     return;
  11822.  
  11823.   if (!type) /* Don't do this for class templates.  */
  11824.     return;
  11825.  
  11826.   for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  11827.     if (TREE_TYPE (decl) == type
  11828.     || (TREE_TYPE (decl)
  11829.         && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  11830.         && TREE_TYPE (TREE_TYPE (decl)) == type))
  11831.       {
  11832.     if (TREE_CODE (decl) == TYPE_DECL)
  11833.       layout_type (TREE_TYPE (decl));
  11834.     else
  11835.       {
  11836.         int toplevel = global_binding_level == current_binding_level;
  11837.         if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  11838.         && TREE_TYPE (TREE_TYPE (decl)) == type)
  11839.           layout_type (TREE_TYPE (decl));
  11840.         layout_decl (decl, 0);
  11841.         rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
  11842.         if (! toplevel)
  11843.           {
  11844.         tree cleanup;
  11845.         expand_decl (decl);
  11846.         cleanup = maybe_build_cleanup (decl);
  11847.         expand_decl_init (decl);
  11848.         if (! expand_decl_cleanup (decl, cleanup))
  11849.           cp_error ("parser lost in parsing declaration of `%D'",
  11850.                 decl);
  11851.           }
  11852.       }
  11853.     my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
  11854.     --current_binding_level->n_incomplete;
  11855.       }
  11856. }
  11857.  
  11858. /* Nonzero if presently building a cleanup.  Needed because
  11859.    SAVE_EXPRs are not the right things to use inside of cleanups.
  11860.    They are only ever evaluated once, where the cleanup
  11861.    might be evaluated several times.  In this case, a later evaluation
  11862.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  11863.    not be valid for an earlier cleanup.  */
  11864.  
  11865. int building_cleanup;
  11866.  
  11867. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  11868.    We don't build cleanups if just going for syntax checking, since
  11869.    fixup_cleanups does not know how to not handle them.
  11870.  
  11871.    Don't build these on the momentary obstack; they must live
  11872.    the life of the binding contour.  */
  11873. tree
  11874. maybe_build_cleanup (decl)
  11875.      tree decl;
  11876. {
  11877.   tree type = TREE_TYPE (decl);
  11878.   if (TYPE_NEEDS_DESTRUCTOR (type))
  11879.     {
  11880.       int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
  11881.       tree rval;
  11882.       int old_building_cleanup = building_cleanup;
  11883.       building_cleanup = 1;
  11884.  
  11885.       if (TREE_CODE (decl) != PARM_DECL)
  11886.     temp = suspend_momentary ();
  11887.  
  11888.       if (TREE_CODE (type) == ARRAY_TYPE)
  11889.     rval = decl;
  11890.       else
  11891.     {
  11892.       mark_addressable (decl);
  11893.       rval = build_unary_op (ADDR_EXPR, decl, 0);
  11894.     }
  11895.  
  11896.       /* Optimize for space over speed here.  */
  11897.       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
  11898.       || flag_expensive_optimizations)
  11899.     flags |= LOOKUP_NONVIRTUAL;
  11900.  
  11901.       /* Use TYPE_MAIN_VARIANT so we don't get a warning about
  11902.      calling delete on a `const' variable.  */
  11903.       if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
  11904.     rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
  11905.  
  11906.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
  11907.  
  11908.       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
  11909.       && ! TYPE_HAS_DESTRUCTOR (type))
  11910.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  11911.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  11912.  
  11913.       if (TREE_CODE (decl) != PARM_DECL)
  11914.     resume_momentary (temp);
  11915.  
  11916.       building_cleanup = old_building_cleanup;
  11917.  
  11918.       return rval;
  11919.     }
  11920.   return 0;
  11921. }
  11922.  
  11923. /* Expand a C++ expression at the statement level.
  11924.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  11925.    The C++ type checker should get all of these out when
  11926.    expressions are combined with other, type-providing, expressions,
  11927.    leaving only orphan expressions, such as:
  11928.  
  11929.    &class::bar;        / / takes its address, but does nothing with it.
  11930.  
  11931.    */
  11932. void
  11933. cplus_expand_expr_stmt (exp)
  11934.      tree exp;
  11935. {
  11936.   if (TREE_TYPE (exp) == unknown_type_node)
  11937.     {
  11938.       if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
  11939.     error ("address of overloaded function with no contextual type information");
  11940.       else if (TREE_CODE (exp) == COMPONENT_REF)
  11941.     warning ("useless reference to a member function name, did you forget the ()?");
  11942.     }
  11943.   else
  11944.     {
  11945.       int remove_implicit_immediately = 0;
  11946.  
  11947.       if (TREE_CODE (exp) == FUNCTION_DECL)
  11948.     {
  11949.       cp_warning ("reference, not call, to function `%D'", exp);
  11950.       warning ("at this point in file");
  11951.     }
  11952.  
  11953. #if 0
  11954.       /* We should do this eventually, but right now this causes regex.o from
  11955.      libg++ to miscompile, and tString to core dump.  */
  11956.       exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
  11957. #endif
  11958.       expand_expr_stmt (break_out_cleanups (exp));
  11959.     }
  11960.  
  11961.   /* Clean up any pending cleanups.  This happens when a function call
  11962.      returns a cleanup-needing value that nobody uses.  */
  11963.   expand_cleanups_to (NULL_TREE);
  11964. }
  11965.  
  11966. /* When a stmt has been parsed, this function is called.
  11967.  
  11968.    Currently, this function only does something within a
  11969.    constructor's scope: if a stmt has just assigned to this,
  11970.    and we are in a derived class, we call `emit_base_init'.  */
  11971.  
  11972. void
  11973. finish_stmt ()
  11974. {
  11975.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  11976.  
  11977.   
  11978.   if (current_function_assigns_this
  11979.       || ! current_function_just_assigned_this)
  11980.     return;
  11981.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  11982.     {
  11983.       /* Constructors must wait until we are out of control
  11984.      zones before calling base constructors.  */
  11985.       if (cond_stack || loop_stack || case_stack)
  11986.     return;
  11987.       emit_insns (base_init_insns);
  11988.       check_base_init (current_class_type);
  11989.     }
  11990.   current_function_assigns_this = 1;
  11991.  
  11992.   if (flag_cadillac)
  11993.     cadillac_finish_stmt ();
  11994. }
  11995.  
  11996. /* Change a static member function definition into a FUNCTION_TYPE, instead
  11997.    of the METHOD_TYPE that we create when it's originally parsed.
  11998.  
  11999.    WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
  12000.    (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
  12001.    other decls.  Either pass the addresses of local variables or NULL.  */
  12002.  
  12003. void
  12004. revert_static_member_fn (decl, fn, argtypes)
  12005.      tree *decl, *fn, *argtypes;
  12006. {
  12007.   tree tmp;
  12008.   tree function = fn ? *fn : TREE_TYPE (*decl);
  12009.   tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
  12010.  
  12011.   args = TREE_CHAIN (args);
  12012.   tmp = build_function_type (TREE_TYPE (function), args);
  12013.   tmp = build_type_variant (tmp, TYPE_READONLY (function),
  12014.                 TYPE_VOLATILE (function));
  12015.   tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
  12016.                  TYPE_RAISES_EXCEPTIONS (function));
  12017.   TREE_TYPE (*decl) = tmp;
  12018.   DECL_STATIC_FUNCTION_P (*decl) = 1;
  12019.   if (fn)
  12020.     *fn = tmp;
  12021.   if (argtypes)
  12022.     *argtypes = args;
  12023. }
  12024.  
  12025. int
  12026. id_in_current_class (id)
  12027.      tree id;
  12028. {
  12029.   return !!purpose_member (id, class_binding_level->class_shadowed);
  12030. }
  12031.